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 _search_with_regex_cbmi;
119 private JCheckBoxMenuItem _show_overview_cbmi;
120 private JMenuItem _choose_minimal_confidence_mi;
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 JCheckBoxMenuItem _show_default_node_shapes_for_marked_cbmi;
127 private JMenuItem _cycle_node_shape_mi;
128 private JMenuItem _cycle_node_fill_mi;
129 private JMenuItem _choose_node_size_mi;
130 private JCheckBoxMenuItem _show_confidence_stddev_cbmi;
131 private final LinkedList<TextFrame> _textframes = new LinkedList<TextFrame>();
132 private JMenu _analysis_menu;
133 private JMenuItem _gsdi_item;
134 private JMenuItem _gsdir_item;
135 private Phylogeny _species_tree;
136 private JCheckBoxMenuItem _right_line_up_domains_cbmi;
137 private JCheckBoxMenuItem _line_up_renderable_data_cbmi;
140 public void actionPerformed( final ActionEvent e ) {
141 final Object o = e.getSource();
142 if ( o == _midpoint_root_item ) {
143 getMainPanel().getCurrentTreePanel().midpointRoot();
145 else if ( o == _gsdi_item ) {
146 if ( isSubtreeDisplayed() ) {
151 else if ( o == _gsdir_item ) {
152 if ( isSubtreeDisplayed() ) {
157 else if ( o == _taxcolor_item ) {
158 getMainPanel().getCurrentTreePanel().taxColor();
160 else if ( o == _confcolor_item ) {
161 getMainPanel().getCurrentTreePanel().confColor();
163 else if ( o == _collapse_species_specific_subtrees ) {
164 if ( getCurrentTreePanel() != null ) {
165 getCurrentTreePanel().collapseSpeciesSpecificSubtrees();
168 else if ( o == _remove_branch_color_item ) {
169 removeBranchColors();
171 else if ( o == _remove_visual_styles_item ) {
172 removeVisualStyles();
174 else if ( o == _switch_colors_mi ) {
177 else if ( o == _display_basic_information_item ) {
178 displayBasicInformation();
180 else if ( o == _view_as_NH_item ) {
183 else if ( o == _view_as_XML_item ) {
186 else if ( o == _view_as_nexus_item ) {
189 else if ( o == _super_tiny_fonts_mi ) {
190 if ( getCurrentTreePanel() != null ) {
191 getCurrentTreePanel().setSuperTinyFonts();
192 getCurrentTreePanel().repaint();
195 else if ( o == _tiny_fonts_mi ) {
196 if ( getCurrentTreePanel() != null ) {
197 getCurrentTreePanel().setTinyFonts();
198 getCurrentTreePanel().repaint();
201 else if ( o == _small_fonts_mi ) {
202 if ( getCurrentTreePanel() != null ) {
203 getCurrentTreePanel().setSmallFonts();
204 getCurrentTreePanel().repaint();
207 else if ( o == _medium_fonts_mi ) {
208 if ( getCurrentTreePanel() != null ) {
209 getCurrentTreePanel().setMediumFonts();
210 getCurrentTreePanel().repaint();
213 else if ( o == _large_fonts_mi ) {
214 if ( getCurrentTreePanel() != null ) {
215 getCurrentTreePanel().setLargeFonts();
216 getCurrentTreePanel().repaint();
219 else if ( o == _choose_font_mi ) {
222 else if ( o == _choose_minimal_confidence_mi ) {
223 chooseMinimalConfidence();
225 else if ( o == _choose_node_size_mi ) {
226 MainFrame.chooseNodeSize( getOptions(), this );
228 else if ( o == _overview_placment_mi ) {
229 MainFrame.cycleOverview( getOptions(), getCurrentTreePanel() );
231 else if ( o == _cycle_node_fill_mi ) {
232 MainFrame.cycleNodeFill( getOptions() );
234 else if ( o == _cycle_node_shape_mi ) {
235 MainFrame.cycleNodeShape( getOptions() );
237 else if ( o == _non_lined_up_cladograms_rbmi ) {
238 updateOptions( getOptions() );
239 _mainpanel.getControlPanel().showWhole();
241 else if ( o == _uniform_cladograms_rbmi ) {
242 updateOptions( getOptions() );
243 _mainpanel.getControlPanel().showWhole();
245 else if ( o == _ext_node_dependent_cladogram_rbmi ) {
246 updateOptions( getOptions() );
247 _mainpanel.getControlPanel().showWhole();
249 else if ( o == _search_case_senstive_cbmi ) {
250 updateOptions( getOptions() );
251 getMainPanel().getControlPanel().search0();
252 getMainPanel().getControlPanel().search1();
254 else if ( o == _search_whole_words_only_cbmi ) {
255 if ( ( _search_with_regex_cbmi != null ) && _search_whole_words_only_cbmi.isSelected() ) {
256 _search_with_regex_cbmi.setSelected( false );
258 updateOptions( getOptions() );
259 getMainPanel().getControlPanel().search0();
260 getMainPanel().getControlPanel().search1();
262 else if ( o == _inverse_search_result_cbmi ) {
263 updateOptions( getOptions() );
264 getMainPanel().getControlPanel().search0();
265 getMainPanel().getControlPanel().search1();
267 else if ( o == _search_with_regex_cbmi ) {
268 if ( ( _search_whole_words_only_cbmi != null ) && _search_with_regex_cbmi.isSelected() ) {
269 _search_whole_words_only_cbmi.setSelected( false );
271 if ( ( _search_case_senstive_cbmi != null ) && _search_with_regex_cbmi.isSelected() ) {
272 _search_case_senstive_cbmi.setSelected( true );
274 updateOptions( getOptions() );
275 getMainPanel().getControlPanel().search0();
276 getMainPanel().getControlPanel().search1();
278 else if ( o == _show_scale_cbmi ) {
279 updateOptions( getOptions() );
281 else if ( o == _show_confidence_stddev_cbmi ) {
282 updateOptions( getOptions() );
284 else if ( o == _label_direction_cbmi ) {
285 updateOptions( getOptions() );
287 else if ( o == _abbreviate_scientific_names ) {
288 updateOptions( getOptions() );
290 else if ( o == _show_overview_cbmi ) {
291 updateOptions( getOptions() );
292 if ( getCurrentTreePanel() != null ) {
293 getCurrentTreePanel().updateOvSizes();
296 else if ( ( o == _rectangular_type_cbmi ) || ( o == _triangular_type_cbmi ) || ( o == _curved_type_cbmi )
297 || ( o == _convex_type_cbmi ) || ( o == _rounded_type_cbmi ) || ( o == _euro_type_cbmi )
298 || ( o == _unrooted_type_cbmi ) || ( o == _circular_type_cbmi ) ) {
301 else if ( o == _screen_antialias_cbmi ) {
302 updateOptions( getOptions() );
303 setupScreenTextAntialias( getMainPanel().getTreePanels(), isScreenAntialias() );
305 else if ( o == _background_gradient_cbmi ) {
306 updateOptions( getOptions() );
308 else if ( o == _show_domain_labels ) {
309 updateOptions( getOptions() );
311 else if ( o == _color_labels_same_as_parent_branch ) {
312 updateOptions( getOptions() );
314 else if ( o == _show_default_node_shapes_internal_cbmi ) {
315 updateOptions( getOptions() );
317 else if ( o == _show_default_node_shapes_external_cbmi ) {
318 updateOptions( getOptions() );
320 else if ( o == _about_item ) {
323 else if ( o == _help_item ) {
325 AptxUtil.openWebsite( Constants.APTX_DOC_SITE, true, this );
327 catch ( final IOException e1 ) {
328 ForesterUtil.printErrorMessage( Constants.PRG_NAME, e1.toString() );
331 else if ( o == _website_item ) {
333 AptxUtil.openWebsite( Constants.APTX_WEB_SITE, true, this );
335 catch ( final IOException e1 ) {
336 ForesterUtil.printErrorMessage( Constants.PRG_NAME, e1.toString() );
339 else if ( o == _phyloxml_website_item ) {
341 AptxUtil.openWebsite( Constants.PHYLOXML_WEB_SITE, true, this );
343 catch ( final IOException e1 ) {
344 ForesterUtil.printErrorMessage( Constants.PRG_NAME, e1.toString() );
347 else if ( o == _aptx_ref_item ) {
349 AptxUtil.openWebsite( Constants.APTX_REFERENCE_URL, true, this );
351 catch ( final IOException e1 ) {
352 ForesterUtil.printErrorMessage( Constants.PRG_NAME, e1.toString() );
355 else if ( o == _phyloxml_ref_item ) {
357 AptxUtil.openWebsite( Constants.PHYLOXML_REFERENCE_URL, true, this );
359 catch ( final IOException e1 ) {
360 ForesterUtil.printErrorMessage( Constants.PRG_NAME, e1.toString() );
363 else if ( o == _color_by_taxonomic_group_cbmi ) {
364 updateOptions( getOptions() );
366 else if ( o == _line_up_renderable_data_cbmi ) {
367 if ( !_line_up_renderable_data_cbmi.isSelected() ) {
368 _right_line_up_domains_cbmi.setSelected( false );
370 updateOptions( getOptions() );
372 else if ( o == _right_line_up_domains_cbmi ) {
373 if ( _right_line_up_domains_cbmi.isSelected() ) {
374 _line_up_renderable_data_cbmi.setSelected( true );
376 updateOptions( getOptions() );
382 public void destroy() {
383 AptxUtil.printAppletMessage( NAME, "going to be destroyed " );
384 removeAllTextFrames();
385 if ( getMainPanel() != null ) {
386 getMainPanel().terminate();
391 * This method returns the current external node data which
392 * has been selected by the user by clicking the "Return ..."
393 * menu item. This method is expected to be called from Javascript or
396 * @return current external node data as String
398 public String getCurrentExternalNodesDataBuffer() {
399 return getCurrentTreePanel().getCurrentExternalNodesDataBufferAsString();
402 public int getCurrentExternalNodesDataBufferChangeCounter() {
403 return getCurrentTreePanel().getCurrentExternalNodesDataBufferChangeCounter();
406 public int getCurrentExternalNodesDataBufferLength() {
407 return getCurrentTreePanel().getCurrentExternalNodesDataBufferAsString().length();
411 * This method returns the current phylogeny as a string in the chosen format
413 * @param format must be NH, NHX, NEXUS or PHYLOXML
414 * @return the phylogeny string
415 * @author Herve Menager
417 public String getCurrentPhylogeny( final String format ) {
418 removeAllTextFrames();
419 if ( ( getMainPanel().getCurrentPhylogeny() == null ) || getMainPanel().getCurrentPhylogeny().isEmpty()
420 || ( getMainPanel().getCurrentPhylogeny().getNumberOfExternalNodes() > 10000 ) ) {
423 switch ( ForesterConstants.PhylogeneticTreeFormats.valueOf( format ) ) {
425 return getMainPanel().getCurrentPhylogeny().toNewHampshire();
427 return getMainPanel().getCurrentPhylogeny().toNewHampshireX();
429 return getMainPanel().getCurrentPhylogeny().toNexus();
431 return getMainPanel().getCurrentPhylogeny().toPhyloXML( -1 );
439 * This method returns a view of the current phylogeny in a chosen
440 * graphics format, base64-encoded in a string so that in can be used
443 * @param format must be GraphicsExportType (gif, jpg, pdf, png, tif, bmp)
444 * @return the phylogeny string
445 * @author Herve Menager
447 public String getCurrentPhylogenyGraphicsAsBase64EncodedString( final String format ) {
448 final ByteArrayOutputStream baos = new ByteArrayOutputStream();
450 AptxUtil.writePhylogenyToGraphicsByteArrayOutputStream( baos,
451 _mainpanel.getWidth(),
452 _mainpanel.getHeight(),
453 getCurrentTreePanel(),
454 getCurrentTreePanel().getControlPanel(),
455 GraphicsExportType.valueOf( format ),
458 catch ( final IOException ioe ) {
459 ForesterUtil.printErrorMessage( NAME, ioe.toString() );
460 ioe.printStackTrace();
461 JOptionPane.showMessageDialog( this,
462 NAME + ": Failed to generate graphics: " + "\nException: " + ioe,
463 "Failed to generate graphics",
464 JOptionPane.ERROR_MESSAGE );
467 final byte[] bytes = baos.toByteArray();
468 final String dataImg = Base64.encodeBase64String( bytes );
472 public Options getOptions() {
478 final String config_filename = getParameter( Constants.APPLET_PARAM_NAME_FOR_CONFIG_FILE_URL );
479 AptxUtil.printAppletMessage( NAME, "URL for configuration file is: " + config_filename );
480 final Configuration configuration = new Configuration( config_filename, true, true, true );
481 setConfiguration( configuration );
482 setOptions( Options.createInstance( configuration ) );
484 final String tree_url_str = getParameter( Constants.APPLET_PARAM_NAME_FOR_URL_OF_TREE_TO_LOAD );
485 if ( ForesterUtil.isEmpty( tree_url_str ) ) {
486 ForesterUtil.printErrorMessage( NAME, "could not get tree URL from "
487 + Constants.APPLET_PARAM_NAME_FOR_URL_OF_TREE_TO_LOAD );
488 JOptionPane.showMessageDialog( this, NAME + ": could not get tree URL from "
489 + Constants.APPLET_PARAM_NAME_FOR_URL_OF_TREE_TO_LOAD, "Failed get URL", JOptionPane.ERROR_MESSAGE );
492 AptxUtil.printAppletMessage( NAME, "URL for phylogenies is " + tree_url_str );
493 // Get URL to tree file
496 phys_url = new URL( tree_url_str );
498 catch ( final Exception e ) {
499 ForesterUtil.printErrorMessage( NAME, "error: " + e );
501 JOptionPane.showMessageDialog( this, NAME + ": Could not create URL from: \"" + tree_url_str
502 + "\"\nException: " + e, "Failed to create URL", JOptionPane.ERROR_MESSAGE );
504 if ( phys_url == null ) {
505 ForesterUtil.printErrorMessage( NAME, "failed to get tree URL from "
506 + Constants.APPLET_PARAM_NAME_FOR_URL_OF_TREE_TO_LOAD );
507 JOptionPane.showMessageDialog( this,
508 NAME + ": Could not create URL from: \"" + tree_url_str,
509 "Failed to create URL",
510 JOptionPane.ERROR_MESSAGE );
513 // Load the tree from URL
514 Phylogeny[] phys = null;
516 phys = AptxUtil.readPhylogeniesFromUrl( phys_url,
517 getConfiguration().isValidatePhyloXmlAgainstSchema(),
518 getConfiguration().isReplaceUnderscoresInNhParsing(),
519 getConfiguration().isInternalNumberAreConfidenceForNhParsing(),
520 getConfiguration().getTaxonomyExtraction(),
521 getConfiguration().isMidpointReroot() );
523 catch ( final Exception e ) {
524 ForesterUtil.printErrorMessage( NAME, e.toString() );
526 JOptionPane.showMessageDialog( this,
527 NAME + ": Failed to read phylogenies: " + "\nException: " + e,
528 "Failed to read phylogenies",
529 JOptionPane.ERROR_MESSAGE );
531 if ( phys == null ) {
532 ForesterUtil.printErrorMessage( NAME, "phylogenies from [" + phys_url + "] are null" );
533 JOptionPane.showMessageDialog( this,
534 NAME + ": phylogenies from [" + phys_url + "] are null",
535 "Failed to read phylogenies",
536 JOptionPane.ERROR_MESSAGE );
539 else if ( phys.length < 1 ) {
540 ForesterUtil.printErrorMessage( NAME, "phylogenies from [" + phys_url + "] are empty" );
541 JOptionPane.showMessageDialog( this,
542 NAME + ": phylogenies from [" + phys_url + "] are empty",
543 "Failed to read phylogenies",
544 JOptionPane.ERROR_MESSAGE );
548 AptxUtil.printAppletMessage( NAME, "loaded " + phys.length + " phylogenies from: " + phys_url );
551 final String species_tree_url_str = getParameter( Constants.APPLET_PARAM_NAME_FOR_URL_OF_SPECIES_TREE_TO_LOAD );
552 if ( !ForesterUtil.isEmpty( species_tree_url_str ) ) {
553 AptxUtil.printAppletMessage( NAME, "URL of species tree to load: \"" + species_tree_url_str + "\"" );
554 Phylogeny[] species_trees = null;
556 final URL species_tree_url = new URL( species_tree_url_str );
557 species_trees = AptxUtil.readPhylogeniesFromUrl( species_tree_url,
558 configuration.isValidatePhyloXmlAgainstSchema(),
559 configuration.isReplaceUnderscoresInNhParsing(),
561 TAXONOMY_EXTRACTION.NO,
564 catch ( final IOException e ) {
565 ForesterUtil.printErrorMessage( NAME, "could not read species tree from [" + species_tree_url_str
567 JOptionPane.showMessageDialog( this, NAME + ": could not read species tree from ["
568 + species_tree_url_str + "]", "Failed to read species tree", JOptionPane.ERROR_MESSAGE );
570 if ( ( species_trees != null ) && ( species_trees.length > 0 ) ) {
571 AptxUtil.printAppletMessage( NAME, "successfully read species tree" );
572 if ( species_trees[ 0 ].isEmpty() ) {
573 ForesterUtil.printErrorMessage( NAME, "species tree is empty" );
575 else if ( !species_trees[ 0 ].isRooted() ) {
576 ForesterUtil.printErrorMessage( NAME, "species tree is not rooted" );
579 setSpeciesTree( species_trees[ 0 ] );
580 AptxUtil.printAppletMessage( NAME, "species tree OK" );
587 setMainPanel( new MainPanelApplets( getConfiguration(), this ) );
588 _jmenubar = new JMenuBar();
589 if ( !getConfiguration().isHideControlPanelAndMenubar() ) {
590 if ( !getConfiguration().isUseNativeUI() ) {
591 _jmenubar.setBackground( getConfiguration().getGuiMenuBackgroundColor() );
593 if ( getSpeciesTree() != null ) {
602 setJMenuBar( _jmenubar );
604 final Container contentpane = getContentPane();
605 contentpane.setLayout( new BorderLayout() );
606 contentpane.add( getMainPanel(), BorderLayout.CENTER );
607 addComponentListener( new ComponentAdapter() {
610 public void componentResized( final ComponentEvent e ) {
611 if ( getMainPanel().getCurrentTreePanel() != null ) {
612 getMainPanel().getCurrentTreePanel().calcParametersForPainting( getMainPanel()
613 .getCurrentTreePanel()
616 .getCurrentTreePanel()
621 if ( getConfiguration().isUseTabbedDisplay() ) {
623 AptxUtil.printAppletMessage( NAME, "using tabbed display" );
624 AptxUtil.addPhylogeniesToTabs( phys,
625 new File( phys_url.getFile() ).getName(),
630 catch ( final Exception e ) {
631 ForesterUtil.printErrorMessage( NAME, e.toString() );
636 AptxUtil.printAppletMessage( NAME, "not using tabbed display" );
637 if ( getSpeciesTree() != null ) {
638 AptxUtil.printAppletMessage( NAME,
639 "Warning: gsdi (gene duplication inference) only available tabbed display" );
641 AptxUtil.addPhylogenyToPanel( phys, getConfiguration(), getMainPanel() );
645 getMainPanel().getControlPanel().showWholeAll();
646 getMainPanel().getControlPanel().showWhole();
648 getCurrentTreePanel().getControlPanel().getSequenceRelationTypeBox().removeAllItems();
649 for( final SequenceRelation.SEQUENCE_RELATION_TYPE type : getMainPanel().getCurrentPhylogeny()
650 .getRelevantSequenceRelationTypes() ) {
651 getCurrentTreePanel().getControlPanel().getSequenceRelationTypeBox().addItem( type );
653 final String default_relation = getParameter( Constants.APPLET_PARAM_NAME_FOR_DEFAULT_SEQUENCE_RELATION_TYPE );
654 if ( default_relation != null ) {
655 getCurrentTreePanel().getControlPanel().getSequenceRelationTypeBox().setSelectedItem( default_relation );
657 final String default_sequence = getParameter( Constants.APPLET_PARAM_NAME_FOR_DEFAULT_QUERY_SEQUENCE );
658 if ( default_sequence != null ) {
659 getCurrentTreePanel().getControlPanel().getSequenceRelationBox().setSelectedItem( default_sequence );
663 AptxUtil.printAppletMessage( NAME, "successfully initialized" );
666 catch ( final Exception e ) {
667 ForesterUtil.printErrorMessage( NAME, e.toString() );
672 public void showTextFrame( final String s, final String title ) {
674 _textframes.addLast( TextFrame.instantiate( s, title, _textframes ) );
678 public void start() {
679 if ( getMainPanel() != null ) {
680 getMainPanel().validate();
683 requestFocusInWindow();
685 AptxUtil.printAppletMessage( NAME, "started" );
688 void buildAnalysisMenu() {
689 _analysis_menu = MainFrame.createMenu( "Analysis", getConfiguration() );
690 _analysis_menu.add( _gsdi_item = new JMenuItem( "GSDI (Generalized Speciation Duplication Inference)" ) );
691 _analysis_menu.add( _gsdir_item = new JMenuItem( "GSDIR (GSDI with re-rooting)" ) );
692 customizeJMenuItem( _gsdi_item );
693 customizeJMenuItem( _gsdir_item );
694 // _analysis_menu.addSeparator();
695 // _analysis_menu.add( _lineage_inference = new JMenuItem( INFER_ANCESTOR_TAXONOMIES ) );
696 // customizeJMenuItem( _lineage_inference );
697 // _lineage_inference.setToolTipText( "Inference of ancestor taxonomies/lineages" );
698 _jmenubar.add( _analysis_menu );
701 void buildFontSizeMenu() {
702 _font_size_menu = MainFrame.createMenu( MainFrame.FONT_SIZE_MENU_LABEL, getConfiguration() );
703 _font_size_menu.add( _super_tiny_fonts_mi = new JMenuItem( "Super tiny fonts" ) );
704 _font_size_menu.add( _tiny_fonts_mi = new JMenuItem( "Tiny fonts" ) );
705 _font_size_menu.add( _small_fonts_mi = new JMenuItem( "Small fonts" ) );
706 _font_size_menu.add( _medium_fonts_mi = new JMenuItem( "Medium fonts" ) );
707 _font_size_menu.add( _large_fonts_mi = new JMenuItem( "Large fonts" ) );
708 customizeJMenuItem( _super_tiny_fonts_mi );
709 customizeJMenuItem( _tiny_fonts_mi );
710 customizeJMenuItem( _small_fonts_mi );
711 customizeJMenuItem( _medium_fonts_mi );
712 customizeJMenuItem( _large_fonts_mi );
713 _jmenubar.add( _font_size_menu );
716 void buildHelpMenu() {
717 _help_jmenu = MainFrame.createMenu( "Help", getConfiguration() );
718 _help_jmenu.add( _help_item = new JMenuItem( "Documentation" ) );
719 _help_jmenu.addSeparator();
720 _help_jmenu.add( _website_item = new JMenuItem( "Archaeopteryx Home" ) );
721 _aptx_ref_item = new JMenuItem( "Archaeopteryx Reference" );
722 _help_jmenu.add( _phyloxml_website_item = new JMenuItem( "phyloXML Home" ) );
723 _help_jmenu.add( _phyloxml_ref_item = new JMenuItem( "phyloXML Reference" ) );
724 _help_jmenu.addSeparator();
725 _help_jmenu.add( _about_item = new JMenuItem( "About" ) );
726 customizeJMenuItem( _help_item );
727 customizeJMenuItem( _website_item );
728 customizeJMenuItem( _phyloxml_website_item );
729 customizeJMenuItem( _aptx_ref_item );
730 customizeJMenuItem( _phyloxml_ref_item );
731 customizeJMenuItem( _about_item );
732 _phyloxml_ref_item.setToolTipText( MainFrame.PHYLOXML_REF_TOOL_TIP );
733 _aptx_ref_item.setToolTipText( MainFrame.APTX_REF_TOOL_TIP );
734 _jmenubar.add( _help_jmenu );
737 void buildOptionsMenu() {
738 _options_jmenu = MainFrame.createMenu( MainFrame.OPTIONS_HEADER, getConfiguration() );
739 _options_jmenu.addChangeListener( new ChangeListener() {
742 public void stateChanged( final ChangeEvent e ) {
743 MainFrame.setOvPlacementColorChooseMenuItem( _overview_placment_mi, getOptions() );
744 MainFrame.setTextColorChooseMenuItem( _switch_colors_mi, getCurrentTreePanel() );
746 .setTextMinSupportMenuItem( _choose_minimal_confidence_mi, getOptions(), getCurrentTreePanel() );
747 MainFrame.setTextForFontChooserMenuItem( _choose_font_mi, MainFrame
748 .createCurrentFontDesc( getMainPanel().getTreeFontSet() ) );
749 MainFrame.setCycleNodeFillMenuItem( _cycle_node_fill_mi, getOptions() );
750 MainFrame.setCycleNodeShapeMenuItem( _cycle_node_shape_mi, getOptions() );
751 MainFrame.setTextNodeSizeMenuItem( _choose_node_size_mi, getOptions() );
753 getMainPanel().getControlPanel().setVisibilityOfDomainStrucureCB();
754 getMainPanel().getControlPanel().setVisibilityOfX();
756 catch ( final Exception ignore ) {
757 // do nothing, not important.
761 _options_jmenu.add( MainFrame.customizeMenuItemAsLabel( new JMenuItem( MainFrame.DISPLAY_SUBHEADER ),
762 getConfiguration() ) );
764 .add( _ext_node_dependent_cladogram_rbmi = new JRadioButtonMenuItem( MainFrame.NONUNIFORM_CLADOGRAMS_LABEL ) );
765 _options_jmenu.add( _uniform_cladograms_rbmi = new JRadioButtonMenuItem( MainFrame.UNIFORM_CLADOGRAMS_LABEL ) );
767 .add( _non_lined_up_cladograms_rbmi = new JRadioButtonMenuItem( MainFrame.NON_LINED_UP_CLADOGRAMS_LABEL ) );
768 _radio_group_1 = new ButtonGroup();
769 _radio_group_1.add( _ext_node_dependent_cladogram_rbmi );
770 _radio_group_1.add( _uniform_cladograms_rbmi );
771 _radio_group_1.add( _non_lined_up_cladograms_rbmi );
772 _options_jmenu.add( _show_overview_cbmi = new JCheckBoxMenuItem( MainFrame.SHOW_OVERVIEW_LABEL ) );
773 _options_jmenu.add( _show_scale_cbmi = new JCheckBoxMenuItem( MainFrame.DISPLAY_SCALE_LABEL ) );
775 .add( _show_default_node_shapes_internal_cbmi = new JCheckBoxMenuItem( MainFrame.DISPLAY_NODE_BOXES_LABEL_INT ) );
777 .add( _show_default_node_shapes_external_cbmi = new JCheckBoxMenuItem( MainFrame.DISPLAY_NODE_BOXES_LABEL_EXT ) );
779 .add( _show_default_node_shapes_for_marked_cbmi = new JCheckBoxMenuItem( MainFrame.DISPLAY_NODE_BOXES_LABEL_MARKED ) );
780 _options_jmenu.add( _line_up_renderable_data_cbmi = new JCheckBoxMenuItem( MainFrame.LINE_UP_RENDERABLE_DATA ) );
781 if ( getConfiguration().doDisplayOption( Configuration.show_domain_architectures ) ) {
782 _options_jmenu.add( _right_line_up_domains_cbmi = new JCheckBoxMenuItem( MainFrame.RIGHT_LINE_UP_DOMAINS ) );
783 _options_jmenu.add( _show_domain_labels = new JCheckBoxMenuItem( MainFrame.SHOW_DOMAIN_LABELS_LABEL ) );
785 _options_jmenu.add( _show_annotation_ref_source = new JCheckBoxMenuItem( MainFrame.SHOW_ANN_REF_SOURCE_LABEL ) );
786 _options_jmenu.add( _show_confidence_stddev_cbmi = new JCheckBoxMenuItem( MainFrame.SHOW_CONF_STDDEV_LABEL ) );
788 .add( _color_by_taxonomic_group_cbmi = new JCheckBoxMenuItem( MainFrame.COLOR_BY_TAXONOMIC_GROUP ) );
790 .add( _color_labels_same_as_parent_branch = new JCheckBoxMenuItem( MainFrame.COLOR_LABELS_LABEL ) );
791 _color_labels_same_as_parent_branch.setToolTipText( MainFrame.COLOR_LABELS_TIP );
792 _options_jmenu.add( _abbreviate_scientific_names = new JCheckBoxMenuItem( MainFrame.ABBREV_SN_LABEL ) );
793 _options_jmenu.add( _label_direction_cbmi = new JCheckBoxMenuItem( MainFrame.LABEL_DIRECTION_LABEL ) );
794 _label_direction_cbmi.setToolTipText( MainFrame.LABEL_DIRECTION_TIP );
795 _options_jmenu.add( _screen_antialias_cbmi = new JCheckBoxMenuItem( MainFrame.SCREEN_ANTIALIAS_LABEL ) );
796 _options_jmenu.add( _background_gradient_cbmi = new JCheckBoxMenuItem( MainFrame.BG_GRAD_LABEL ) );
797 _options_jmenu.add( _cycle_node_shape_mi = new JMenuItem( MainFrame.CYCLE_NODE_SHAPE_LABEL ) );
798 _options_jmenu.add( _cycle_node_fill_mi = new JMenuItem( MainFrame.CYCLE_NODE_FILL_LABEL ) );
799 _options_jmenu.add( _choose_node_size_mi = new JMenuItem( MainFrame.CHOOSE_NODE_SIZE_LABEL ) );
800 _options_jmenu.add( _choose_minimal_confidence_mi = new JMenuItem( "" ) );
801 _options_jmenu.add( _overview_placment_mi = new JMenuItem( "" ) );
802 _options_jmenu.add( _switch_colors_mi = new JMenuItem( "" ) );
803 _options_jmenu.add( _choose_font_mi = new JMenuItem( "" ) );
804 _options_jmenu.addSeparator();
805 _options_jmenu.add( MainFrame.customizeMenuItemAsLabel( new JMenuItem( MainFrame.SEARCH_SUBHEADER ),
806 getConfiguration() ) );
808 .add( _search_case_senstive_cbmi = new JCheckBoxMenuItem( MainFrame.SEARCH_CASE_SENSITIVE_LABEL ) );
809 _options_jmenu.add( _search_whole_words_only_cbmi = new JCheckBoxMenuItem( MainFrame.SEARCH_TERMS_ONLY_LABEL ) );
810 _options_jmenu.add( _search_with_regex_cbmi = new JCheckBoxMenuItem( MainFrame.SEARCH_REGEX_LABEL ) );
811 _search_with_regex_cbmi.setToolTipText( MainFrame.SEARCH_WITH_REGEX_TIP );
813 .add( _inverse_search_result_cbmi = new JCheckBoxMenuItem( MainFrame.INVERSE_SEARCH_RESULT_LABEL ) );
814 customizeJMenuItem( _choose_font_mi );
815 customizeJMenuItem( _choose_minimal_confidence_mi );
816 customizeJMenuItem( _switch_colors_mi );
817 customizeJMenuItem( _overview_placment_mi );
818 customizeCheckBoxMenuItem( _color_by_taxonomic_group_cbmi, getOptions().isColorByTaxonomicGroup() );
819 customizeCheckBoxMenuItem( _label_direction_cbmi,
820 getOptions().getNodeLabelDirection() == NODE_LABEL_DIRECTION.RADIAL );
821 customizeCheckBoxMenuItem( _screen_antialias_cbmi, getOptions().isAntialiasScreen() );
822 customizeCheckBoxMenuItem( _background_gradient_cbmi, getOptions().isBackgroundColorGradient() );
823 customizeCheckBoxMenuItem( _show_domain_labels, getOptions().isShowDomainLabels() );
824 customizeCheckBoxMenuItem( _show_annotation_ref_source, getOptions().isShowAnnotationRefSource() );
825 customizeCheckBoxMenuItem( _abbreviate_scientific_names, getOptions().isAbbreviateScientificTaxonNames() );
826 customizeCheckBoxMenuItem( _show_default_node_shapes_external_cbmi, getOptions()
827 .isShowDefaultNodeShapesExternal() );
828 customizeCheckBoxMenuItem( _show_default_node_shapes_internal_cbmi, getOptions()
829 .isShowDefaultNodeShapesInternal() );
830 customizeCheckBoxMenuItem( _show_default_node_shapes_for_marked_cbmi, getOptions()
831 .isShowDefaultNodeShapesForMarkedNodes() );
832 customizeJMenuItem( _cycle_node_shape_mi );
833 customizeJMenuItem( _cycle_node_fill_mi );
834 customizeJMenuItem( _choose_node_size_mi );
835 customizeCheckBoxMenuItem( _color_labels_same_as_parent_branch, getOptions().isColorLabelsSameAsParentBranch() );
836 customizeCheckBoxMenuItem( _search_case_senstive_cbmi, getOptions().isSearchCaseSensitive() );
837 customizeCheckBoxMenuItem( _show_scale_cbmi, getOptions().isShowScale() );
838 customizeRadioButtonMenuItem( _non_lined_up_cladograms_rbmi,
839 getOptions().getCladogramType() == CLADOGRAM_TYPE.NON_LINED_UP );
840 customizeRadioButtonMenuItem( _uniform_cladograms_rbmi,
841 getOptions().getCladogramType() == CLADOGRAM_TYPE.TOTAL_NODE_SUM_DEP );
842 customizeRadioButtonMenuItem( _ext_node_dependent_cladogram_rbmi,
843 getOptions().getCladogramType() == CLADOGRAM_TYPE.EXT_NODE_SUM_DEP );
844 customizeCheckBoxMenuItem( _show_overview_cbmi, getOptions().isShowOverview() );
845 customizeCheckBoxMenuItem( _search_with_regex_cbmi, getOptions().isSearchWithRegex() );
846 customizeCheckBoxMenuItem( _search_whole_words_only_cbmi, getOptions().isMatchWholeTermsOnly() );
847 customizeCheckBoxMenuItem( _inverse_search_result_cbmi, getOptions().isInverseSearchResult() );
848 customizeCheckBoxMenuItem( _show_confidence_stddev_cbmi, getOptions().isShowConfidenceStddev() );
849 customizeCheckBoxMenuItem( _line_up_renderable_data_cbmi, getOptions().isLineUpRendarableNodeData() );
850 customizeCheckBoxMenuItem( _right_line_up_domains_cbmi, getOptions().isRightLineUpDomains() );
851 _jmenubar.add( _options_jmenu );
854 void buildToolsMenu() {
855 _tools_menu = MainFrame.createMenu( "Tools", getConfiguration() );
856 _tools_menu.add( _confcolor_item = new JMenuItem( "Colorize Branches Depending on Confidence" ) );
857 customizeJMenuItem( _confcolor_item );
858 _tools_menu.add( _taxcolor_item = new JMenuItem( "Taxonomy Colorize Branches" ) );
859 customizeJMenuItem( _taxcolor_item );
860 _tools_menu.addSeparator();
861 _tools_menu.add( _remove_visual_styles_item = new JMenuItem( "Delete All Visual Styles From Nodes" ) );
862 _remove_visual_styles_item
863 .setToolTipText( "To remove all node visual styles (fonts, colors) from the current phylogeny." );
864 customizeJMenuItem( _remove_visual_styles_item );
865 _tools_menu.add( _remove_branch_color_item = new JMenuItem( "Delete All Colors From Branches" ) );
866 _remove_branch_color_item.setToolTipText( "To remove all branch color values from the current phylogeny." );
867 customizeJMenuItem( _remove_branch_color_item );
868 _tools_menu.addSeparator();
869 _tools_menu.add( _midpoint_root_item = new JMenuItem( "Midpoint-Root" ) );
870 customizeJMenuItem( _midpoint_root_item );
871 _tools_menu.addSeparator();
872 _tools_menu.add( _collapse_species_specific_subtrees = new JMenuItem( "Collapse Species-Specific Subtrees" ) );
873 customizeJMenuItem( _collapse_species_specific_subtrees );
874 _jmenubar.add( _tools_menu );
877 void buildTypeMenu() {
878 _type_menu = MainFrame.createMenu( MainFrame.TYPE_MENU_HEADER, getConfiguration() );
879 _type_menu.add( _rectangular_type_cbmi = new JCheckBoxMenuItem( MainFrame.RECTANGULAR_TYPE_CBMI_LABEL ) );
880 _type_menu.add( _euro_type_cbmi = new JCheckBoxMenuItem( MainFrame.EURO_TYPE_CBMI_LABEL ) );
881 _type_menu.add( _rounded_type_cbmi = new JCheckBoxMenuItem( MainFrame.ROUNDED_TYPE_CBMI_LABEL ) );
882 _type_menu.add( _curved_type_cbmi = new JCheckBoxMenuItem( MainFrame.CURVED_TYPE_CBMI_LABEL ) );
883 _type_menu.add( _triangular_type_cbmi = new JCheckBoxMenuItem( MainFrame.TRIANGULAR_TYPE_CBMI_LABEL ) );
884 _type_menu.add( _convex_type_cbmi = new JCheckBoxMenuItem( MainFrame.CONVEX_TYPE_CBMI_LABEL ) );
885 _type_menu.add( _unrooted_type_cbmi = new JCheckBoxMenuItem( MainFrame.UNROOTED_TYPE_CBMI_LABEL ) );
886 _type_menu.add( _circular_type_cbmi = new JCheckBoxMenuItem( MainFrame.CIRCULAR_TYPE_CBMI_LABEL ) );
887 customizeCheckBoxMenuItem( _rectangular_type_cbmi, false );
888 customizeCheckBoxMenuItem( _triangular_type_cbmi, false );
889 customizeCheckBoxMenuItem( _euro_type_cbmi, false );
890 customizeCheckBoxMenuItem( _rounded_type_cbmi, false );
891 customizeCheckBoxMenuItem( _curved_type_cbmi, false );
892 customizeCheckBoxMenuItem( _convex_type_cbmi, false );
893 customizeCheckBoxMenuItem( _unrooted_type_cbmi, false );
894 customizeCheckBoxMenuItem( _circular_type_cbmi, false );
895 _unrooted_type_cbmi.setToolTipText( MainFrame.USE_MOUSEWHEEL_SHIFT_TO_ROTATE );
896 _circular_type_cbmi.setToolTipText( MainFrame.USE_MOUSEWHEEL_SHIFT_TO_ROTATE );
897 initializeTypeMenu( getOptions() );
898 _jmenubar.add( _type_menu );
901 void buildViewMenu() {
902 _view_jmenu = MainFrame.createMenu( "View", getConfiguration() );
904 .add( _display_basic_information_item = new JMenuItem( MainFrame.SHOW_BASIC_TREE_INFORMATION_LABEL ) );
905 _view_jmenu.addSeparator();
906 _view_jmenu.add( _view_as_XML_item = new JMenuItem( "as phyloXML" ) );
907 _view_jmenu.add( _view_as_NH_item = new JMenuItem( "as Newick" ) );
908 _view_jmenu.add( _view_as_nexus_item = new JMenuItem( "as Nexus" ) );
909 customizeJMenuItem( _display_basic_information_item );
910 customizeJMenuItem( _view_as_NH_item );
911 customizeJMenuItem( _view_as_XML_item );
912 customizeJMenuItem( _view_as_nexus_item );
913 _jmenubar.add( _view_jmenu );
916 void checkTextFrames() {
917 if ( _textframes.size() > 5 ) {
919 if ( _textframes.getFirst() != null ) {
920 _textframes.getFirst().removeMe();
923 _textframes.removeFirst();
926 catch ( final NoSuchElementException e ) {
932 void clearCurrentExternalNodesDataBuffer() {
933 getCurrentTreePanel().clearCurrentExternalNodesDataBuffer();
936 void customizeCheckBoxMenuItem( final JCheckBoxMenuItem item, final boolean is_selected ) {
937 if ( item != null ) {
938 item.setFont( MainFrame.menu_font );
939 if ( !getConfiguration().isUseNativeUI() ) {
940 item.setBackground( getConfiguration().getGuiMenuBackgroundColor() );
941 item.setForeground( getConfiguration().getGuiMenuTextColor() );
943 item.setSelected( is_selected );
944 item.addActionListener( this );
948 void customizeJMenuItem( final JMenuItem jmi ) {
949 jmi.setFont( MainFrame.menu_font );
950 if ( !getConfiguration().isUseNativeUI() ) {
951 jmi.setBackground( getConfiguration().getGuiMenuBackgroundColor() );
952 jmi.setForeground( getConfiguration().getGuiMenuTextColor() );
954 jmi.addActionListener( this );
957 void displayBasicInformation() {
958 if ( ( getMainPanel() != null ) && ( getMainPanel().getCurrentPhylogeny() != null )
959 && !getMainPanel().getCurrentPhylogeny().isEmpty() ) {
960 String title = "Basic Information";
961 if ( !ForesterUtil.isEmpty( getMainPanel().getCurrentPhylogeny().getName() ) ) {
962 title = title + " for \"" + _mainpanel.getCurrentPhylogeny().getName() + "\"";
964 showTextFrame( AptxUtil.createBasicInformation( getMainPanel().getCurrentPhylogeny(), null ), title );
969 if ( !isOKforSDI( false, true ) ) {
972 if ( !_mainpanel.getCurrentPhylogeny().isRooted() ) {
973 JOptionPane.showMessageDialog( this,
974 "Gene tree is not rooted.",
975 "Cannot execute GSDI",
976 JOptionPane.ERROR_MESSAGE );
979 final Phylogeny gene_tree = _mainpanel.getCurrentPhylogeny().copy();
980 gene_tree.setAllNodesToNotCollapse();
981 gene_tree.recalculateNumberOfExternalDescendants( false );
983 final Phylogeny species_tree = _species_tree.copy();
985 gsdi = new GSDI( gene_tree, species_tree, false, true, true, true );
987 catch ( final SDIException e ) {
988 JOptionPane.showMessageDialog( this,
989 e.getLocalizedMessage(),
991 JOptionPane.ERROR_MESSAGE );
994 catch ( final Exception e ) {
995 AptxUtil.unexpectedException( e );
998 gene_tree.setRerootable( false );
999 gene_tree.clearHashIdToNodeMap();
1000 gene_tree.recalculateNumberOfExternalDescendants( true );
1001 _mainpanel.addPhylogenyInNewTab( gene_tree, getConfiguration(), "gene tree", null );
1002 getMainPanel().getControlPanel().setShowEvents( true );
1004 final int selected = _mainpanel.getTabbedPane().getSelectedIndex();
1005 _mainpanel.addPhylogenyInNewTab( species_tree, getConfiguration(), "species tree", null );
1007 _mainpanel.getTabbedPane().setSelectedIndex( selected );
1009 _mainpanel.getCurrentTreePanel().setEdited( true );
1010 final int poly = PhylogenyMethods.countNumberOfPolytomies( species_tree );
1011 if ( gsdi.getStrippedExternalGeneTreeNodes().size() > 0 ) {
1012 JOptionPane.showMessageDialog( this,
1013 "Duplications: " + gsdi.getDuplicationsSum() + "\n"
1014 + "Potential duplications: "
1015 + gsdi.getSpeciationOrDuplicationEventsSum() + "\n"
1016 + "Speciations: " + gsdi.getSpeciationsSum() + "\n"
1017 + "Stripped gene tree nodes: "
1018 + gsdi.getStrippedExternalGeneTreeNodes().size() + "\n"
1019 + "Taxonomy linkage based on: " + gsdi.getTaxCompBase() + "\n"
1020 + "Number of polytomies in species tree used: " + poly + "\n",
1021 "GSDI successfully completed",
1022 JOptionPane.WARNING_MESSAGE );
1025 JOptionPane.showMessageDialog( this,
1026 "Duplications: " + gsdi.getDuplicationsSum() + "\n"
1027 + "Potential duplications: "
1028 + gsdi.getSpeciationOrDuplicationEventsSum() + "\n"
1029 + "Speciations: " + gsdi.getSpeciationsSum() + "\n"
1030 + "Stripped gene tree nodes: "
1031 + gsdi.getStrippedExternalGeneTreeNodes().size() + "\n"
1032 + "Taxonomy linkage based on: " + gsdi.getTaxCompBase() + "\n"
1033 + "Number of polytomies in species tree used: " + poly + "\n",
1034 "GSDI successfully completed",
1035 JOptionPane.INFORMATION_MESSAGE );
1039 void executeGSDIR() {
1040 if ( !isOKforSDI( false, false ) ) {
1043 final int p = PhylogenyMethods.countNumberOfPolytomies( _mainpanel.getCurrentPhylogeny() );
1045 && !( ( p == 1 ) && ( _mainpanel.getCurrentPhylogeny().getRoot().getNumberOfDescendants() == 3 ) ) ) {
1046 JOptionPane.showMessageDialog( this,
1047 "Gene tree is not completely binary",
1048 "Cannot execute GSDI",
1049 JOptionPane.ERROR_MESSAGE );
1052 final Phylogeny gene_tree = _mainpanel.getCurrentPhylogeny().copy();
1053 gene_tree.setAllNodesToNotCollapse();
1054 gene_tree.recalculateNumberOfExternalDescendants( false );
1056 final Phylogeny species_tree = _species_tree.copy();
1058 gsdir = new GSDIR( gene_tree, species_tree, true, true, true );
1060 catch ( final SDIException e ) {
1061 JOptionPane.showMessageDialog( this,
1062 e.getLocalizedMessage(),
1063 "Error during GSDIR",
1064 JOptionPane.ERROR_MESSAGE );
1067 catch ( final Exception e ) {
1068 AptxUtil.unexpectedException( e );
1071 final Phylogeny result_gene_tree = gsdir.getMinDuplicationsSumGeneTree();
1072 result_gene_tree.setRerootable( false );
1073 result_gene_tree.clearHashIdToNodeMap();
1074 result_gene_tree.recalculateNumberOfExternalDescendants( true );
1075 PhylogenyMethods.orderAppearance( result_gene_tree.getRoot(), true, true, DESCENDANT_SORT_PRIORITY.NODE_NAME );
1076 _mainpanel.addPhylogenyInNewTab( result_gene_tree, getConfiguration(), "gene tree", null );
1077 getMainPanel().getControlPanel().setShowEvents( true );
1079 final int selected = _mainpanel.getTabbedPane().getSelectedIndex();
1080 _mainpanel.addPhylogenyInNewTab( species_tree, getConfiguration(), "species tree", null );
1082 _mainpanel.getTabbedPane().setSelectedIndex( selected );
1084 _mainpanel.getCurrentTreePanel().setEdited( true );
1085 final int poly = PhylogenyMethods.countNumberOfPolytomies( species_tree );
1086 if ( gsdir.getStrippedExternalGeneTreeNodes().size() > 0 ) {
1087 JOptionPane.showMessageDialog( this,
1088 "Minimal duplications: " + gsdir.getMinDuplicationsSum() + "\n"
1089 + "Speciations: " + gsdir.getSpeciationsSum() + "\n"
1090 + "Stripped gene tree nodes: "
1091 + gsdir.getStrippedExternalGeneTreeNodes().size() + "\n"
1092 + "Taxonomy linkage based on: " + gsdir.getTaxCompBase() + "\n"
1093 + "Number of polytomies in species tree used: " + poly + "\n",
1094 "GSDIR successfully completed",
1095 JOptionPane.WARNING_MESSAGE );
1098 JOptionPane.showMessageDialog( this,
1099 "Minimal duplications: " + gsdir.getMinDuplicationsSum() + "\n"
1100 + "Speciations: " + gsdir.getSpeciationsSum() + "\n"
1101 + "Stripped gene tree nodes: "
1102 + gsdir.getStrippedExternalGeneTreeNodes().size() + "\n"
1103 + "Taxonomy linkage based on: " + gsdir.getTaxCompBase() + "\n"
1104 + "Number of polytomies in species tree used: " + poly + "\n",
1105 "GSDIR successfully completed",
1106 JOptionPane.INFORMATION_MESSAGE );
1110 Configuration getConfiguration() {
1111 return _configuration;
1114 TreePanel getCurrentTreePanel() {
1115 return getMainPanel().getCurrentTreePanel();
1118 JCheckBoxMenuItem getlabelDirectionCbmi() {
1119 return _label_direction_cbmi;
1122 Options getOtions() {
1126 void initializeTypeMenu( final Options options ) {
1127 setTypeMenuToAllUnselected();
1129 switch ( options.getPhylogenyGraphicsType() ) {
1131 _convex_type_cbmi.setSelected( true );
1134 _curved_type_cbmi.setSelected( true );
1137 _euro_type_cbmi.setSelected( true );
1140 _rounded_type_cbmi.setSelected( true );
1143 _triangular_type_cbmi.setSelected( true );
1146 _unrooted_type_cbmi.setSelected( true );
1149 _circular_type_cbmi.setSelected( true );
1152 _rectangular_type_cbmi.setSelected( true );
1156 catch ( final NullPointerException np ) {
1157 // In all likelihood, this is caused by menu-less display.
1161 boolean isOKforSDI( final boolean species_tree_has_to_binary, final boolean gene_tree_has_to_binary ) {
1162 if ( ( _mainpanel.getCurrentPhylogeny() == null ) || _mainpanel.getCurrentPhylogeny().isEmpty() ) {
1165 else if ( ( _species_tree == null ) || _species_tree.isEmpty() ) {
1166 JOptionPane.showMessageDialog( this,
1167 "No species tree loaded",
1168 "Cannot execute GSDI",
1169 JOptionPane.ERROR_MESSAGE );
1172 else if ( species_tree_has_to_binary && !_species_tree.isCompletelyBinary() ) {
1173 JOptionPane.showMessageDialog( this,
1174 "Species tree is not completely binary",
1175 "Cannot execute GSDI",
1176 JOptionPane.ERROR_MESSAGE );
1179 else if ( gene_tree_has_to_binary && !_mainpanel.getCurrentPhylogeny().isCompletelyBinary() ) {
1180 JOptionPane.showMessageDialog( this,
1181 "Gene tree is not completely binary",
1182 "Cannot execute GSDI",
1183 JOptionPane.ERROR_MESSAGE );
1191 boolean isSubtreeDisplayed() {
1192 if ( getCurrentTreePanel() != null ) {
1193 if ( getCurrentTreePanel().isCurrentTreeIsSubtree() ) {
1195 .showMessageDialog( this,
1196 "This operation can only be performed on a complete tree, not on the currently displayed sub-tree only.",
1197 "Operation can not be exectuted on a sub-tree",
1198 JOptionPane.WARNING_MESSAGE );
1205 void removeAllTextFrames() {
1206 for( final TextFrame tf : _textframes ) {
1211 _textframes.clear();
1214 void setConfiguration( final Configuration configuration ) {
1215 _configuration = configuration;
1218 void setOptions( final Options options ) {
1222 void setSelectedTypeInTypeMenu( final PHYLOGENY_GRAPHICS_TYPE type ) {
1223 setTypeMenuToAllUnselected();
1227 _circular_type_cbmi.setSelected( true );
1230 _convex_type_cbmi.setSelected( true );
1233 _curved_type_cbmi.setSelected( true );
1236 _euro_type_cbmi.setSelected( true );
1239 _rounded_type_cbmi.setSelected( true );
1242 _rectangular_type_cbmi.setSelected( true );
1245 _triangular_type_cbmi.setSelected( true );
1248 _unrooted_type_cbmi.setSelected( true );
1251 throw new IllegalArgumentException( "unknown type: " + type );
1254 catch ( final NullPointerException np ) {
1255 // In all likelihood, this is caused by menu-less display.
1259 void setTypeMenuToAllUnselected() {
1260 if ( _convex_type_cbmi != null ) {
1261 _convex_type_cbmi.setSelected( false );
1263 if ( _curved_type_cbmi != null ) {
1264 _curved_type_cbmi.setSelected( false );
1266 if ( _euro_type_cbmi != null ) {
1267 _euro_type_cbmi.setSelected( false );
1269 if ( _rounded_type_cbmi != null ) {
1270 _rounded_type_cbmi.setSelected( false );
1272 if ( _triangular_type_cbmi != null ) {
1273 _triangular_type_cbmi.setSelected( false );
1275 if ( _rectangular_type_cbmi != null ) {
1276 _rectangular_type_cbmi.setSelected( false );
1278 if ( _unrooted_type_cbmi != null ) {
1279 _unrooted_type_cbmi.setSelected( false );
1281 if ( _circular_type_cbmi != null ) {
1282 _circular_type_cbmi.setSelected( false );
1287 _mainpanel.getControlPanel().showWhole();
1290 void switchColors() {
1291 final TreeColorSet colorset = getMainPanel().getCurrentTreePanel().getTreeColorSet();
1292 final ColorSchemeChooser csc = new ColorSchemeChooser( getMainPanel(), colorset );
1293 csc.setVisible( true );
1294 getMainPanel().setTreeColorSet( colorset );
1297 void typeChanged( final Object o ) {
1298 updateTypeCheckboxes( getOptions(), o );
1299 updateOptions( getOptions() );
1300 if ( getCurrentTreePanel() != null ) {
1301 final PHYLOGENY_GRAPHICS_TYPE previous_type = getCurrentTreePanel().getPhylogenyGraphicsType();
1302 final PHYLOGENY_GRAPHICS_TYPE new_type = getOptions().getPhylogenyGraphicsType();
1303 if ( ( ( previous_type == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) && ( new_type != PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) )
1304 || ( ( previous_type == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) && ( new_type != PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) )
1305 || ( ( previous_type != PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) && ( new_type == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) )
1306 || ( ( previous_type != PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) && ( new_type == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) ) ) {
1307 getCurrentTreePanel().getControlPanel().showWhole();
1309 if ( getCurrentTreePanel().isPhyHasBranchLengths() && ( new_type != PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) ) {
1310 getCurrentTreePanel().getControlPanel().setDrawPhylogramEnabled( true );
1313 getCurrentTreePanel().getControlPanel().setDrawPhylogramEnabled( false );
1315 getCurrentTreePanel().setPhylogenyGraphicsType( getOptions().getPhylogenyGraphicsType() );
1316 MainFrame.updateScreenTextAntialias( getMainPanel().getTreePanels() );
1320 void updateOptions( final Options options ) {
1321 options.setAntialiasScreen( ( _screen_antialias_cbmi != null ) && _screen_antialias_cbmi.isSelected() );
1322 options.setBackgroundColorGradient( ( _background_gradient_cbmi != null )
1323 && _background_gradient_cbmi.isSelected() );
1324 options.setShowDomainLabels( ( _show_domain_labels != null ) && _show_domain_labels.isSelected() );
1325 options.setShowAnnotationRefSource( ( _show_annotation_ref_source != null )
1326 && _show_annotation_ref_source.isSelected() );
1327 options.setAbbreviateScientificTaxonNames( ( _abbreviate_scientific_names != null )
1328 && _abbreviate_scientific_names.isSelected() );
1329 options.setColorLabelsSameAsParentBranch( ( _color_labels_same_as_parent_branch != null )
1330 && _color_labels_same_as_parent_branch.isSelected() );
1331 options.setShowDefaultNodeShapesInternal( ( _show_default_node_shapes_internal_cbmi != null )
1332 && _show_default_node_shapes_internal_cbmi.isSelected() );
1333 options.setShowDefaultNodeShapesExternal( ( _show_default_node_shapes_external_cbmi != null )
1334 && _show_default_node_shapes_external_cbmi.isSelected() );
1335 options.setShowDefaultNodeShapesForMarkedNodes( ( _show_default_node_shapes_for_marked_cbmi != null )
1336 && _show_default_node_shapes_for_marked_cbmi.isSelected() );
1337 if ( ( _non_lined_up_cladograms_rbmi != null ) && ( _non_lined_up_cladograms_rbmi.isSelected() ) ) {
1338 options.setCladogramType( CLADOGRAM_TYPE.NON_LINED_UP );
1340 else if ( ( _uniform_cladograms_rbmi != null ) && ( _uniform_cladograms_rbmi.isSelected() ) ) {
1341 options.setCladogramType( CLADOGRAM_TYPE.TOTAL_NODE_SUM_DEP );
1343 else if ( ( _ext_node_dependent_cladogram_rbmi != null ) && ( _ext_node_dependent_cladogram_rbmi.isSelected() ) ) {
1344 options.setCladogramType( CLADOGRAM_TYPE.EXT_NODE_SUM_DEP );
1346 options.setSearchCaseSensitive( ( _search_case_senstive_cbmi != null )
1347 && _search_case_senstive_cbmi.isSelected() );
1348 if ( ( _show_scale_cbmi != null ) && _show_scale_cbmi.isEnabled() ) {
1349 options.setShowScale( _show_scale_cbmi.isSelected() );
1351 if ( _label_direction_cbmi != null ) {
1352 if ( _label_direction_cbmi.isSelected() ) {
1353 options.setNodeLabelDirection( NODE_LABEL_DIRECTION.RADIAL );
1356 options.setNodeLabelDirection( NODE_LABEL_DIRECTION.HORIZONTAL );
1359 options.setShowOverview( ( _show_overview_cbmi != null ) && _show_overview_cbmi.isSelected() );
1360 options.setShowConfidenceStddev( ( _show_confidence_stddev_cbmi != null )
1361 && _show_confidence_stddev_cbmi.isSelected() );
1362 options.setMatchWholeTermsOnly( ( _search_whole_words_only_cbmi != null )
1363 && _search_whole_words_only_cbmi.isSelected() );
1364 options.setSearchWithRegex( ( _search_with_regex_cbmi != null ) && _search_with_regex_cbmi.isSelected() );
1365 options.setInverseSearchResult( ( _inverse_search_result_cbmi != null )
1366 && _inverse_search_result_cbmi.isSelected() );
1367 if ( ( _rectangular_type_cbmi != null ) && _rectangular_type_cbmi.isSelected() ) {
1368 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR );
1370 else if ( ( _triangular_type_cbmi != null ) && _triangular_type_cbmi.isSelected() ) {
1371 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.TRIANGULAR );
1373 else if ( ( _curved_type_cbmi != null ) && _curved_type_cbmi.isSelected() ) {
1374 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CURVED );
1376 else if ( ( _convex_type_cbmi != null ) && _convex_type_cbmi.isSelected() ) {
1377 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CONVEX );
1379 else if ( ( _euro_type_cbmi != null ) && _euro_type_cbmi.isSelected() ) {
1380 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE );
1382 else if ( ( _rounded_type_cbmi != null ) && _rounded_type_cbmi.isSelected() ) {
1383 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.ROUNDED );
1385 else if ( ( _unrooted_type_cbmi != null ) && _unrooted_type_cbmi.isSelected() ) {
1386 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.UNROOTED );
1388 else if ( ( _circular_type_cbmi != null ) && _circular_type_cbmi.isSelected() ) {
1389 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CIRCULAR );
1391 if ( ( _color_by_taxonomic_group_cbmi != null ) && _color_by_taxonomic_group_cbmi.isEnabled() ) {
1392 options.setColorByTaxonomicGroup( _color_by_taxonomic_group_cbmi.isSelected() );
1394 if ( ( _right_line_up_domains_cbmi != null ) && _right_line_up_domains_cbmi.isEnabled() ) {
1395 options.setRightLineUpDomains( _right_line_up_domains_cbmi.isSelected() );
1397 if ( ( _line_up_renderable_data_cbmi != null ) && _line_up_renderable_data_cbmi.isEnabled() ) {
1398 options.setLineUpRendarableNodeData( _line_up_renderable_data_cbmi.isSelected() );
1402 void updateTypeCheckboxes( final Options options, final Object o ) {
1403 setTypeMenuToAllUnselected();
1404 ( ( JCheckBoxMenuItem ) o ).setSelected( true );
1407 void viewAsNexus() {
1408 if ( ( getMainPanel().getCurrentPhylogeny() != null ) && !getMainPanel().getCurrentPhylogeny().isEmpty() ) {
1409 String title = "Nexus";
1410 if ( !ForesterUtil.isEmpty( getMainPanel().getCurrentPhylogeny().getName() ) ) {
1411 title = "\"" + getMainPanel().getCurrentPhylogeny().getName() + "\" in " + title;
1413 showTextFrame( getMainPanel().getCurrentPhylogeny().toNexus( getOptions()
1414 .getNhConversionSupportValueStyle() ),
1420 if ( ( getMainPanel().getCurrentPhylogeny() != null ) && !getMainPanel().getCurrentPhylogeny().isEmpty() ) {
1421 String title = "New Hampshire";
1422 if ( !ForesterUtil.isEmpty( getMainPanel().getCurrentPhylogeny().getName() ) ) {
1423 title = "\"" + getMainPanel().getCurrentPhylogeny().getName() + "\" in " + title;
1425 showTextFrame( getMainPanel().getCurrentPhylogeny().toNewHampshire( getOptions()
1426 .getNhConversionSupportValueStyle() ),
1432 if ( ( getMainPanel().getCurrentPhylogeny() != null ) && !getMainPanel().getCurrentPhylogeny().isEmpty() ) {
1433 String title = "phyloXML";
1434 if ( !ForesterUtil.isEmpty( getMainPanel().getCurrentPhylogeny().getName() ) ) {
1435 title = "\"" + getMainPanel().getCurrentPhylogeny().getName() + "\" in " + title;
1437 showTextFrame( getMainPanel().getCurrentPhylogeny().toPhyloXML( 0 ), title );
1441 private void chooseFont() {
1442 final FontChooser fc = new FontChooser();
1443 fc.setFont( getMainPanel().getTreeFontSet().getLargeFont() );
1444 fc.showDialog( this, "Select the Base Font" );
1445 getMainPanel().getTreeFontSet().setBaseFont( fc.getFont() );
1448 private void chooseMinimalConfidence() {
1449 final String s = ( String ) JOptionPane
1450 .showInputDialog( this,
1451 "Please the minimum for confidence values to be displayed.\n" + "[current value: "
1452 + getOptions().getMinConfidenceValue() + "]\n",
1453 "Minimal Confidence Value",
1454 JOptionPane.QUESTION_MESSAGE,
1457 getOptions().getMinConfidenceValue() );
1458 if ( !ForesterUtil.isEmpty( s ) ) {
1459 boolean success = true;
1461 final String m_str = s.trim();
1462 if ( !ForesterUtil.isEmpty( m_str ) ) {
1464 m = Double.parseDouble( m_str );
1466 catch ( final Exception ex ) {
1473 if ( success && ( m >= 0.0 ) ) {
1474 getOptions().setMinConfidenceValue( m );
1479 private void customizeRadioButtonMenuItem( final JRadioButtonMenuItem item, final boolean is_selected ) {
1480 if ( item != null ) {
1481 item.setFont( MainFrame.menu_font );
1482 if ( !getConfiguration().isUseNativeUI() ) {
1483 item.setBackground( getConfiguration().getGuiMenuBackgroundColor() );
1484 item.setForeground( getConfiguration().getGuiMenuTextColor() );
1486 item.setSelected( is_selected );
1487 item.addActionListener( this );
1491 MainPanel getMainPanel() {
1495 private Phylogeny getSpeciesTree() {
1496 return _species_tree;
1499 private boolean isScreenAntialias() {
1503 private void removeBranchColors() {
1504 if ( getMainPanel().getCurrentPhylogeny() != null ) {
1505 AptxUtil.removeBranchColors( getMainPanel().getCurrentPhylogeny() );
1509 private void removeVisualStyles() {
1510 if ( getMainPanel().getCurrentPhylogeny() != null ) {
1511 AptxUtil.removeVisualStyles( getMainPanel().getCurrentPhylogeny() );
1515 private void setMainPanel( final MainPanelApplets main_panel ) {
1516 _mainpanel = main_panel;
1519 private void setSpeciesTree( final Phylogeny species_tree ) {
1520 _species_tree = species_tree;
1523 private void setupUI() {
1525 if ( getConfiguration().isUseNativeUI() ) {
1526 UIManager.setLookAndFeel( UIManager.getSystemLookAndFeelClassName() );
1529 UIManager.setLookAndFeel( UIManager.getCrossPlatformLookAndFeelClassName() );
1532 catch ( final UnsupportedLookAndFeelException e ) {
1533 AptxUtil.dieWithSystemError( "UnsupportedLookAndFeelException: " + e.toString() );
1535 catch ( final ClassNotFoundException e ) {
1536 AptxUtil.dieWithSystemError( "ClassNotFoundException: " + e.toString() );
1538 catch ( final InstantiationException e ) {
1539 AptxUtil.dieWithSystemError( "InstantiationException: " + e.toString() );
1541 catch ( final IllegalAccessException e ) {
1542 AptxUtil.dieWithSystemError( "IllegalAccessException: " + e.toString() );
1544 catch ( final Exception e ) {
1545 AptxUtil.dieWithSystemError( e.toString() );
1549 static void setupScreenTextAntialias( final List<TreePanel> treepanels, final boolean antialias ) {
1550 for( final TreePanel tree_panel : treepanels ) {
1551 tree_panel.setTextAntialias();