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;
120 private JCheckBoxMenuItem _show_overview_cbmi;
121 private JMenuItem _choose_minimal_confidence_mi;
122 private JMenuItem _collapse_species_specific_subtrees;
123 private JMenuItem _overview_placment_mi;
124 private ButtonGroup _radio_group_1;
125 private JCheckBoxMenuItem _show_default_node_shapes_internal_cbmi;
126 private JCheckBoxMenuItem _show_default_node_shapes_external_cbmi;
127 private JCheckBoxMenuItem _show_default_node_shapes_for_marked_cbmi;
128 private JMenuItem _cycle_node_shape_mi;
129 private JMenuItem _cycle_node_fill_mi;
130 private JMenuItem _choose_node_size_mi;
131 private JCheckBoxMenuItem _show_confidence_stddev_cbmi;
132 private final LinkedList<TextFrame> _textframes = new LinkedList<TextFrame>();
133 private JMenu _analysis_menu;
134 private JMenuItem _gsdi_item;
135 private JMenuItem _gsdir_item;
136 private Phylogeny _species_tree;
137 private JCheckBoxMenuItem _right_line_up_domains_cbmi;
138 private JCheckBoxMenuItem _line_up_renderable_data_cbmi;
141 public void actionPerformed( final ActionEvent e ) {
142 final Object o = e.getSource();
143 if ( o == _midpoint_root_item ) {
144 getMainPanel().getCurrentTreePanel().midpointRoot();
146 else if ( o == _gsdi_item ) {
147 if ( isSubtreeDisplayed() ) {
152 else if ( o == _gsdir_item ) {
153 if ( isSubtreeDisplayed() ) {
158 else if ( o == _taxcolor_item ) {
159 getMainPanel().getCurrentTreePanel().taxColor();
161 else if ( o == _confcolor_item ) {
162 getMainPanel().getCurrentTreePanel().confColor();
164 else if ( o == _collapse_species_specific_subtrees ) {
165 if ( getCurrentTreePanel() != null ) {
166 getCurrentTreePanel().collapseSpeciesSpecificSubtrees();
169 else if ( o == _remove_branch_color_item ) {
170 removeBranchColors();
172 else if ( o == _remove_visual_styles_item ) {
173 removeVisualStyles();
175 else if ( o == _switch_colors_mi ) {
178 else if ( o == _display_basic_information_item ) {
179 displayBasicInformation();
181 else if ( o == _view_as_NH_item ) {
184 else if ( o == _view_as_XML_item ) {
187 else if ( o == _view_as_nexus_item ) {
190 else if ( o == _super_tiny_fonts_mi ) {
191 if ( getCurrentTreePanel() != null ) {
192 getCurrentTreePanel().setSuperTinyFonts();
193 getCurrentTreePanel().repaint();
196 else if ( o == _tiny_fonts_mi ) {
197 if ( getCurrentTreePanel() != null ) {
198 getCurrentTreePanel().setTinyFonts();
199 getCurrentTreePanel().repaint();
202 else if ( o == _small_fonts_mi ) {
203 if ( getCurrentTreePanel() != null ) {
204 getCurrentTreePanel().setSmallFonts();
205 getCurrentTreePanel().repaint();
208 else if ( o == _medium_fonts_mi ) {
209 if ( getCurrentTreePanel() != null ) {
210 getCurrentTreePanel().setMediumFonts();
211 getCurrentTreePanel().repaint();
214 else if ( o == _large_fonts_mi ) {
215 if ( getCurrentTreePanel() != null ) {
216 getCurrentTreePanel().setLargeFonts();
217 getCurrentTreePanel().repaint();
220 else if ( o == _choose_font_mi ) {
223 else if ( o == _choose_minimal_confidence_mi ) {
224 chooseMinimalConfidence();
226 else if ( o == _choose_node_size_mi ) {
227 MainFrame.chooseNodeSize( getOptions(), this );
229 else if ( o == _overview_placment_mi ) {
230 MainFrame.cycleOverview( getOptions(), getCurrentTreePanel() );
232 else if ( o == _cycle_node_fill_mi ) {
233 MainFrame.cycleNodeFill( getOptions(), getCurrentTreePanel() );
235 else if ( o == _cycle_node_shape_mi ) {
236 MainFrame.cycleNodeShape( getOptions(), getCurrentTreePanel() );
238 else if ( o == _non_lined_up_cladograms_rbmi ) {
239 updateOptions( getOptions() );
240 _mainpanel.getControlPanel().showWhole();
242 else if ( o == _uniform_cladograms_rbmi ) {
243 updateOptions( getOptions() );
244 _mainpanel.getControlPanel().showWhole();
246 else if ( o == _ext_node_dependent_cladogram_rbmi ) {
247 updateOptions( getOptions() );
248 _mainpanel.getControlPanel().showWhole();
250 else if ( o == _search_case_senstive_cbmi ) {
251 updateOptions( getOptions() );
252 getMainPanel().getControlPanel().search0();
253 getMainPanel().getControlPanel().search1();
255 else if ( o == _search_whole_words_only_cbmi ) {
256 updateOptions( getOptions() );
257 getMainPanel().getControlPanel().search0();
258 getMainPanel().getControlPanel().search1();
260 else if ( o == _inverse_search_result_cbmi ) {
261 updateOptions( getOptions() );
262 getMainPanel().getControlPanel().search0();
263 getMainPanel().getControlPanel().search1();
265 else if ( o == _search_with_regex_cbmi ) {
266 updateOptions( getOptions() );
267 getMainPanel().getControlPanel().search0();
268 getMainPanel().getControlPanel().search1();
270 else if ( o == _show_scale_cbmi ) {
271 updateOptions( getOptions() );
273 else if ( o == _show_confidence_stddev_cbmi ) {
274 updateOptions( getOptions() );
276 else if ( o == _label_direction_cbmi ) {
277 updateOptions( getOptions() );
279 else if ( o == _abbreviate_scientific_names ) {
280 updateOptions( getOptions() );
282 else if ( o == _show_overview_cbmi ) {
283 updateOptions( getOptions() );
284 if ( getCurrentTreePanel() != null ) {
285 getCurrentTreePanel().updateOvSizes();
288 else if ( ( o == _rectangular_type_cbmi ) || ( o == _triangular_type_cbmi ) || ( o == _curved_type_cbmi )
289 || ( o == _convex_type_cbmi ) || ( o == _rounded_type_cbmi ) || ( o == _euro_type_cbmi )
290 || ( o == _unrooted_type_cbmi ) || ( o == _circular_type_cbmi ) ) {
293 else if ( o == _screen_antialias_cbmi ) {
294 updateOptions( getOptions() );
295 setupScreenTextAntialias( getMainPanel().getTreePanels(), isScreenAntialias() );
297 else if ( o == _background_gradient_cbmi ) {
298 updateOptions( getOptions() );
300 else if ( o == _show_domain_labels ) {
301 updateOptions( getOptions() );
303 else if ( o == _color_labels_same_as_parent_branch ) {
304 updateOptions( getOptions() );
306 else if ( o == _show_default_node_shapes_internal_cbmi ) {
307 updateOptions( getOptions() );
309 else if ( o == _show_default_node_shapes_external_cbmi ) {
310 updateOptions( getOptions() );
312 else if ( o == _about_item ) {
315 else if ( o == _help_item ) {
317 AptxUtil.openWebsite( Constants.APTX_DOC_SITE, true, this );
319 catch ( final IOException e1 ) {
320 ForesterUtil.printErrorMessage( Constants.PRG_NAME, e1.toString() );
323 else if ( o == _website_item ) {
325 AptxUtil.openWebsite( Constants.APTX_WEB_SITE, true, this );
327 catch ( final IOException e1 ) {
328 ForesterUtil.printErrorMessage( Constants.PRG_NAME, e1.toString() );
331 else if ( o == _phyloxml_website_item ) {
333 AptxUtil.openWebsite( Constants.PHYLOXML_WEB_SITE, true, this );
335 catch ( final IOException e1 ) {
336 ForesterUtil.printErrorMessage( Constants.PRG_NAME, e1.toString() );
339 else if ( o == _aptx_ref_item ) {
341 AptxUtil.openWebsite( Constants.APTX_REFERENCE_URL, true, this );
343 catch ( final IOException e1 ) {
344 ForesterUtil.printErrorMessage( Constants.PRG_NAME, e1.toString() );
347 else if ( o == _phyloxml_ref_item ) {
349 AptxUtil.openWebsite( Constants.PHYLOXML_REFERENCE_URL, true, this );
351 catch ( final IOException e1 ) {
352 ForesterUtil.printErrorMessage( Constants.PRG_NAME, e1.toString() );
355 else if ( o == _color_by_taxonomic_group_cbmi ) {
356 updateOptions( getOptions() );
358 else if ( o == _line_up_renderable_data_cbmi ) {
359 if ( !_line_up_renderable_data_cbmi.isSelected() ) {
360 _right_line_up_domains_cbmi.setSelected( false );
362 updateOptions( getOptions() );
364 else if ( o == _right_line_up_domains_cbmi ) {
365 if ( _right_line_up_domains_cbmi.isSelected() ) {
366 _line_up_renderable_data_cbmi.setSelected( true );
368 updateOptions( getOptions() );
374 public void destroy() {
375 AptxUtil.printAppletMessage( NAME, "going to be destroyed " );
376 removeAllTextFrames();
377 if ( getMainPanel() != null ) {
378 getMainPanel().terminate();
383 * This method returns the current external node data which
384 * has been selected by the user by clicking the "Return ..."
385 * menu item. This method is expected to be called from Javascript or
388 * @return current external node data as String
390 public String getCurrentExternalNodesDataBuffer() {
391 return getCurrentTreePanel().getCurrentExternalNodesDataBufferAsString();
394 public int getCurrentExternalNodesDataBufferChangeCounter() {
395 return getCurrentTreePanel().getCurrentExternalNodesDataBufferChangeCounter();
398 public int getCurrentExternalNodesDataBufferLength() {
399 return getCurrentTreePanel().getCurrentExternalNodesDataBufferAsString().length();
403 * This method returns the current phylogeny as a string in the chosen format
405 * @param format must be NH, NHX, NEXUS or PHYLOXML
406 * @return the phylogeny string
407 * @author Herve Menager
409 public String getCurrentPhylogeny( final String format ) {
410 removeAllTextFrames();
411 if ( ( getMainPanel().getCurrentPhylogeny() == null ) || getMainPanel().getCurrentPhylogeny().isEmpty()
412 || ( getMainPanel().getCurrentPhylogeny().getNumberOfExternalNodes() > 10000 ) ) {
415 switch ( ForesterConstants.PhylogeneticTreeFormats.valueOf( format ) ) {
417 return getMainPanel().getCurrentPhylogeny().toNewHampshire();
419 return getMainPanel().getCurrentPhylogeny().toNewHampshireX();
421 return getMainPanel().getCurrentPhylogeny().toNexus();
423 return getMainPanel().getCurrentPhylogeny().toPhyloXML( -1 );
431 * This method returns a view of the current phylogeny in a chosen
432 * graphics format, base64-encoded in a string so that in can be used
435 * @param format must be GraphicsExportType (gif, jpg, pdf, png, tif, bmp)
436 * @return the phylogeny string
437 * @author Herve Menager
439 public String getCurrentPhylogenyGraphicsAsBase64EncodedString( final String format ) {
440 final ByteArrayOutputStream baos = new ByteArrayOutputStream();
442 AptxUtil.writePhylogenyToGraphicsByteArrayOutputStream( baos,
443 _mainpanel.getWidth(),
444 _mainpanel.getHeight(),
445 getCurrentTreePanel(),
446 getCurrentTreePanel().getControlPanel(),
447 GraphicsExportType.valueOf( format ),
450 catch ( final IOException ioe ) {
451 ForesterUtil.printErrorMessage( NAME, ioe.toString() );
452 ioe.printStackTrace();
453 JOptionPane.showMessageDialog( this,
454 NAME + ": Failed to generate graphics: " + "\nException: " + ioe,
455 "Failed to generate graphics",
456 JOptionPane.ERROR_MESSAGE );
459 final byte[] bytes = baos.toByteArray();
460 final String dataImg = Base64.encodeBase64String( bytes );
464 public Options getOptions() {
470 final String config_filename = getParameter( Constants.APPLET_PARAM_NAME_FOR_CONFIG_FILE_URL );
471 AptxUtil.printAppletMessage( NAME, "URL for configuration file is: " + config_filename );
472 final Configuration configuration = new Configuration( config_filename, true, true, true );
473 setConfiguration( configuration );
474 setOptions( Options.createInstance( configuration ) );
476 final String tree_url_str = getParameter( Constants.APPLET_PARAM_NAME_FOR_URL_OF_TREE_TO_LOAD );
477 if ( ForesterUtil.isEmpty( tree_url_str ) ) {
478 ForesterUtil.printErrorMessage( NAME, "could not get tree URL from "
479 + Constants.APPLET_PARAM_NAME_FOR_URL_OF_TREE_TO_LOAD );
480 JOptionPane.showMessageDialog( this, NAME + ": could not get tree URL from "
481 + Constants.APPLET_PARAM_NAME_FOR_URL_OF_TREE_TO_LOAD, "Failed get URL", JOptionPane.ERROR_MESSAGE );
484 AptxUtil.printAppletMessage( NAME, "URL for phylogenies is " + tree_url_str );
485 // Get URL to tree file
488 phys_url = new URL( tree_url_str );
490 catch ( final Exception e ) {
491 ForesterUtil.printErrorMessage( NAME, "error: " + e );
493 JOptionPane.showMessageDialog( this, NAME + ": Could not create URL from: \"" + tree_url_str
494 + "\"\nException: " + e, "Failed to create URL", JOptionPane.ERROR_MESSAGE );
496 if ( phys_url == null ) {
497 ForesterUtil.printErrorMessage( NAME, "failed to get tree URL from "
498 + Constants.APPLET_PARAM_NAME_FOR_URL_OF_TREE_TO_LOAD );
499 JOptionPane.showMessageDialog( this,
500 NAME + ": Could not create URL from: \"" + tree_url_str,
501 "Failed to create URL",
502 JOptionPane.ERROR_MESSAGE );
505 // Load the tree from URL
506 Phylogeny[] phys = null;
508 phys = AptxUtil.readPhylogeniesFromUrl( phys_url,
509 getConfiguration().isValidatePhyloXmlAgainstSchema(),
510 getConfiguration().isReplaceUnderscoresInNhParsing(),
511 getConfiguration().isInternalNumberAreConfidenceForNhParsing(),
512 getConfiguration().getTaxonomyExtraction(),
513 getConfiguration().isMidpointReroot() );
515 catch ( final Exception e ) {
516 ForesterUtil.printErrorMessage( NAME, e.toString() );
518 JOptionPane.showMessageDialog( this,
519 NAME + ": Failed to read phylogenies: " + "\nException: " + e,
520 "Failed to read phylogenies",
521 JOptionPane.ERROR_MESSAGE );
523 if ( phys == null ) {
524 ForesterUtil.printErrorMessage( NAME, "phylogenies from [" + phys_url + "] are null" );
525 JOptionPane.showMessageDialog( this,
526 NAME + ": phylogenies from [" + phys_url + "] are null",
527 "Failed to read phylogenies",
528 JOptionPane.ERROR_MESSAGE );
531 else if ( phys.length < 1 ) {
532 ForesterUtil.printErrorMessage( NAME, "phylogenies from [" + phys_url + "] are empty" );
533 JOptionPane.showMessageDialog( this,
534 NAME + ": phylogenies from [" + phys_url + "] are empty",
535 "Failed to read phylogenies",
536 JOptionPane.ERROR_MESSAGE );
540 AptxUtil.printAppletMessage( NAME, "loaded " + phys.length + " phylogenies from: " + phys_url );
543 final String species_tree_url_str = getParameter( Constants.APPLET_PARAM_NAME_FOR_URL_OF_SPECIES_TREE_TO_LOAD );
544 if ( !ForesterUtil.isEmpty( species_tree_url_str ) ) {
545 AptxUtil.printAppletMessage( NAME, "URL of species tree to load: \"" + species_tree_url_str + "\"" );
546 Phylogeny[] species_trees = null;
548 final URL species_tree_url = new URL( species_tree_url_str );
549 species_trees = AptxUtil.readPhylogeniesFromUrl( species_tree_url,
550 configuration.isValidatePhyloXmlAgainstSchema(),
551 configuration.isReplaceUnderscoresInNhParsing(),
553 TAXONOMY_EXTRACTION.NO,
556 catch ( final IOException e ) {
557 ForesterUtil.printErrorMessage( NAME, "could not read species tree from [" + species_tree_url_str
559 JOptionPane.showMessageDialog( this, NAME + ": could not read species tree from ["
560 + species_tree_url_str + "]", "Failed to read species tree", JOptionPane.ERROR_MESSAGE );
562 if ( ( species_trees != null ) && ( species_trees.length > 0 ) ) {
563 AptxUtil.printAppletMessage( NAME, "successfully read species tree" );
564 if ( species_trees[ 0 ].isEmpty() ) {
565 ForesterUtil.printErrorMessage( NAME, "species tree is empty" );
567 else if ( !species_trees[ 0 ].isRooted() ) {
568 ForesterUtil.printErrorMessage( NAME, "species tree is not rooted" );
571 setSpeciesTree( species_trees[ 0 ] );
572 AptxUtil.printAppletMessage( NAME, "species tree OK" );
579 setMainPanel( new MainPanelApplets( getConfiguration(), this ) );
580 _jmenubar = new JMenuBar();
581 if ( !getConfiguration().isHideControlPanelAndMenubar() ) {
582 if ( !getConfiguration().isUseNativeUI() ) {
583 _jmenubar.setBackground( getConfiguration().getGuiMenuBackgroundColor() );
585 if ( getSpeciesTree() != null ) {
594 setJMenuBar( _jmenubar );
596 final Container contentpane = getContentPane();
597 contentpane.setLayout( new BorderLayout() );
598 contentpane.add( getMainPanel(), BorderLayout.CENTER );
599 addComponentListener( new ComponentAdapter() {
602 public void componentResized( final ComponentEvent e ) {
603 if ( getMainPanel().getCurrentTreePanel() != null ) {
604 getMainPanel().getCurrentTreePanel()
605 .calcParametersForPainting( getMainPanel().getCurrentTreePanel().getWidth(),
606 getMainPanel().getCurrentTreePanel().getHeight(),
607 getOptions().isAllowFontSizeChange() );
611 if ( getConfiguration().isUseTabbedDisplay() ) {
613 AptxUtil.printAppletMessage( NAME, "using tabbed display" );
614 AptxUtil.addPhylogeniesToTabs( phys,
615 new File( phys_url.getFile() ).getName(),
620 catch ( final Exception e ) {
621 ForesterUtil.printErrorMessage( NAME, e.toString() );
626 AptxUtil.printAppletMessage( NAME, "not using tabbed display" );
627 if ( getSpeciesTree() != null ) {
628 AptxUtil.printAppletMessage( NAME,
629 "Warning: gsdi (gene duplication inference) only available tabbed display" );
631 AptxUtil.addPhylogenyToPanel( phys, getConfiguration(), getMainPanel() );
635 getMainPanel().getControlPanel().showWholeAll();
636 getMainPanel().getControlPanel().showWhole();
638 getCurrentTreePanel().getControlPanel().getSequenceRelationTypeBox().removeAllItems();
639 for( final SequenceRelation.SEQUENCE_RELATION_TYPE type : getMainPanel().getCurrentPhylogeny()
640 .getRelevantSequenceRelationTypes() ) {
641 getCurrentTreePanel().getControlPanel().getSequenceRelationTypeBox().addItem( type );
643 final String default_relation = getParameter( Constants.APPLET_PARAM_NAME_FOR_DEFAULT_SEQUENCE_RELATION_TYPE );
644 if ( default_relation != null ) {
645 getCurrentTreePanel().getControlPanel().getSequenceRelationTypeBox().setSelectedItem( default_relation );
647 final String default_sequence = getParameter( Constants.APPLET_PARAM_NAME_FOR_DEFAULT_QUERY_SEQUENCE );
648 if ( default_sequence != null ) {
649 getCurrentTreePanel().getControlPanel().getSequenceRelationBox().setSelectedItem( default_sequence );
653 AptxUtil.printAppletMessage( NAME, "successfully initialized" );
656 catch ( final Exception e ) {
657 ForesterUtil.printErrorMessage( NAME, e.toString() );
662 public void showTextFrame( final String s, final String title ) {
664 _textframes.addLast( TextFrame.instantiate( s, title, _textframes ) );
668 public void start() {
669 if ( getMainPanel() != null ) {
670 getMainPanel().validate();
673 requestFocusInWindow();
675 AptxUtil.printAppletMessage( NAME, "started" );
678 void buildAnalysisMenu() {
679 _analysis_menu = MainFrame.createMenu( "Analysis", getConfiguration() );
680 _analysis_menu.add( _gsdi_item = new JMenuItem( "GSDI (Generalized Speciation Duplication Inference)" ) );
681 _analysis_menu.add( _gsdir_item = new JMenuItem( "GSDIR (GSDI with re-rooting)" ) );
682 customizeJMenuItem( _gsdi_item );
683 customizeJMenuItem( _gsdir_item );
684 // _analysis_menu.addSeparator();
685 // _analysis_menu.add( _lineage_inference = new JMenuItem( INFER_ANCESTOR_TAXONOMIES ) );
686 // customizeJMenuItem( _lineage_inference );
687 // _lineage_inference.setToolTipText( "Inference of ancestor taxonomies/lineages" );
688 _jmenubar.add( _analysis_menu );
691 void buildFontSizeMenu() {
692 _font_size_menu = MainFrame.createMenu( MainFrame.FONT_SIZE_MENU_LABEL, getConfiguration() );
693 _font_size_menu.add( _super_tiny_fonts_mi = new JMenuItem( "Super tiny fonts" ) );
694 _font_size_menu.add( _tiny_fonts_mi = new JMenuItem( "Tiny fonts" ) );
695 _font_size_menu.add( _small_fonts_mi = new JMenuItem( "Small fonts" ) );
696 _font_size_menu.add( _medium_fonts_mi = new JMenuItem( "Medium fonts" ) );
697 _font_size_menu.add( _large_fonts_mi = new JMenuItem( "Large fonts" ) );
698 customizeJMenuItem( _super_tiny_fonts_mi );
699 customizeJMenuItem( _tiny_fonts_mi );
700 customizeJMenuItem( _small_fonts_mi );
701 customizeJMenuItem( _medium_fonts_mi );
702 customizeJMenuItem( _large_fonts_mi );
703 _jmenubar.add( _font_size_menu );
706 void buildHelpMenu() {
707 _help_jmenu = MainFrame.createMenu( "Help", getConfiguration() );
708 _help_jmenu.add( _help_item = new JMenuItem( "Documentation" ) );
709 _help_jmenu.addSeparator();
710 _help_jmenu.add( _website_item = new JMenuItem( "Archaeopteryx Home" ) );
711 _aptx_ref_item = new JMenuItem( "Archaeopteryx Reference" );
712 _help_jmenu.add( _phyloxml_website_item = new JMenuItem( "phyloXML Home" ) );
713 _help_jmenu.add( _phyloxml_ref_item = new JMenuItem( "phyloXML Reference" ) );
714 _help_jmenu.addSeparator();
715 _help_jmenu.add( _about_item = new JMenuItem( "About" ) );
716 customizeJMenuItem( _help_item );
717 customizeJMenuItem( _website_item );
718 customizeJMenuItem( _phyloxml_website_item );
719 customizeJMenuItem( _aptx_ref_item );
720 customizeJMenuItem( _phyloxml_ref_item );
721 customizeJMenuItem( _about_item );
722 _phyloxml_ref_item.setToolTipText( MainFrame.PHYLOXML_REF_TOOL_TIP );
723 _aptx_ref_item.setToolTipText( MainFrame.APTX_REF_TOOL_TIP );
724 _jmenubar.add( _help_jmenu );
727 void buildOptionsMenu() {
728 _options_jmenu = MainFrame.createMenu( MainFrame.OPTIONS_HEADER, getConfiguration() );
729 _options_jmenu.addChangeListener( new ChangeListener() {
732 public void stateChanged( final ChangeEvent e ) {
733 MainFrame.setOvPlacementColorChooseMenuItem( _overview_placment_mi, getOptions() );
734 MainFrame.setTextColorChooseMenuItem( _switch_colors_mi, getCurrentTreePanel() );
736 .setTextMinSupportMenuItem( _choose_minimal_confidence_mi, getOptions(), getCurrentTreePanel() );
737 MainFrame.setTextForFontChooserMenuItem( _choose_font_mi, MainFrame
738 .createCurrentFontDesc( getMainPanel().getTreeFontSet() ) );
739 MainFrame.setCycleNodeFillMenuItem( _cycle_node_fill_mi, getOptions() );
740 MainFrame.setCycleNodeShapeMenuItem( _cycle_node_shape_mi, getOptions() );
741 MainFrame.setTextNodeSizeMenuItem( _choose_node_size_mi, getOptions() );
743 getMainPanel().getControlPanel().setVisibilityOfDomainStrucureCB();
744 getMainPanel().getControlPanel().setVisibilityOfX();
746 catch ( final Exception ignore ) {
747 // do nothing, not important.
751 _options_jmenu.add( MainFrame.customizeMenuItemAsLabel( new JMenuItem( MainFrame.DISPLAY_SUBHEADER ),
752 getConfiguration() ) );
754 .add( _ext_node_dependent_cladogram_rbmi = new JRadioButtonMenuItem( MainFrame.NONUNIFORM_CLADOGRAMS_LABEL ) );
755 _options_jmenu.add( _uniform_cladograms_rbmi = new JRadioButtonMenuItem( MainFrame.UNIFORM_CLADOGRAMS_LABEL ) );
757 .add( _non_lined_up_cladograms_rbmi = new JRadioButtonMenuItem( MainFrame.NON_LINED_UP_CLADOGRAMS_LABEL ) );
758 _radio_group_1 = new ButtonGroup();
759 _radio_group_1.add( _ext_node_dependent_cladogram_rbmi );
760 _radio_group_1.add( _uniform_cladograms_rbmi );
761 _radio_group_1.add( _non_lined_up_cladograms_rbmi );
762 _options_jmenu.add( _show_overview_cbmi = new JCheckBoxMenuItem( MainFrame.SHOW_OVERVIEW_LABEL ) );
763 _options_jmenu.add( _show_scale_cbmi = new JCheckBoxMenuItem( MainFrame.DISPLAY_SCALE_LABEL ) );
765 .add( _show_default_node_shapes_internal_cbmi = new JCheckBoxMenuItem( MainFrame.DISPLAY_NODE_BOXES_LABEL_INT ) );
767 .add( _show_default_node_shapes_external_cbmi = new JCheckBoxMenuItem( MainFrame.DISPLAY_NODE_BOXES_LABEL_EXT ) );
769 .add( _show_default_node_shapes_for_marked_cbmi = new JCheckBoxMenuItem( MainFrame.DISPLAY_NODE_BOXES_LABEL_EXT ) );
770 _options_jmenu.add( _line_up_renderable_data_cbmi = new JCheckBoxMenuItem( MainFrame.LINE_UP_RENDERABLE_DATA ) );
771 if ( getConfiguration().doDisplayOption( Configuration.show_domain_architectures ) ) {
772 _options_jmenu.add( _right_line_up_domains_cbmi = new JCheckBoxMenuItem( MainFrame.RIGHT_LINE_UP_DOMAINS ) );
773 _options_jmenu.add( _show_domain_labels = new JCheckBoxMenuItem( MainFrame.SHOW_DOMAIN_LABELS_LABEL ) );
775 _options_jmenu.add( _show_annotation_ref_source = new JCheckBoxMenuItem( MainFrame.SHOW_ANN_REF_SOURCE_LABEL ) );
776 _options_jmenu.add( _show_confidence_stddev_cbmi = new JCheckBoxMenuItem( MainFrame.SHOW_CONF_STDDEV_LABEL ) );
778 .add( _color_by_taxonomic_group_cbmi = new JCheckBoxMenuItem( MainFrame.COLOR_BY_TAXONOMIC_GROUP ) );
780 .add( _color_labels_same_as_parent_branch = new JCheckBoxMenuItem( MainFrame.COLOR_LABELS_LABEL ) );
781 _color_labels_same_as_parent_branch.setToolTipText( MainFrame.COLOR_LABELS_TIP );
782 _options_jmenu.add( _abbreviate_scientific_names = new JCheckBoxMenuItem( MainFrame.ABBREV_SN_LABEL ) );
783 _options_jmenu.add( _label_direction_cbmi = new JCheckBoxMenuItem( MainFrame.LABEL_DIRECTION_LABEL ) );
784 _label_direction_cbmi.setToolTipText( MainFrame.LABEL_DIRECTION_TIP );
785 _options_jmenu.add( _screen_antialias_cbmi = new JCheckBoxMenuItem( MainFrame.SCREEN_ANTIALIAS_LABEL ) );
786 _options_jmenu.add( _background_gradient_cbmi = new JCheckBoxMenuItem( MainFrame.BG_GRAD_LABEL ) );
787 _options_jmenu.add( _cycle_node_shape_mi = new JMenuItem( MainFrame.CYCLE_NODE_SHAPE_LABEL ) );
788 _options_jmenu.add( _cycle_node_fill_mi = new JMenuItem( MainFrame.CYCLE_NODE_FILL_LABEL ) );
789 _options_jmenu.add( _choose_node_size_mi = new JMenuItem( MainFrame.CHOOSE_NODE_SIZE_LABEL ) );
790 _options_jmenu.add( _choose_minimal_confidence_mi = new JMenuItem( "" ) );
791 _options_jmenu.add( _overview_placment_mi = new JMenuItem( "" ) );
792 _options_jmenu.add( _switch_colors_mi = new JMenuItem( "" ) );
793 _options_jmenu.add( _choose_font_mi = new JMenuItem( "" ) );
794 _options_jmenu.addSeparator();
795 _options_jmenu.add( MainFrame.customizeMenuItemAsLabel( new JMenuItem( MainFrame.SEARCH_SUBHEADER ),
796 getConfiguration() ) );
798 .add( _search_case_senstive_cbmi = new JCheckBoxMenuItem( MainFrame.SEARCH_CASE_SENSITIVE_LABEL ) );
799 _options_jmenu.add( _search_whole_words_only_cbmi = new JCheckBoxMenuItem( MainFrame.SEARCH_TERMS_ONLY_LABEL ) );
804 .add( _search_with_regex_cbmi = new JCheckBoxMenuItem( MainFrame.SEARCH_REGEX_LABEL ) );
811 .add( _inverse_search_result_cbmi = new JCheckBoxMenuItem( MainFrame.INVERSE_SEARCH_RESULT_LABEL ) );
812 customizeJMenuItem( _choose_font_mi );
813 customizeJMenuItem( _choose_minimal_confidence_mi );
814 customizeJMenuItem( _switch_colors_mi );
815 customizeJMenuItem( _overview_placment_mi );
816 customizeCheckBoxMenuItem( _color_by_taxonomic_group_cbmi, getOptions().isColorByTaxonomicGroup() );
817 customizeCheckBoxMenuItem( _label_direction_cbmi,
818 getOptions().getNodeLabelDirection() == NODE_LABEL_DIRECTION.RADIAL );
819 customizeCheckBoxMenuItem( _screen_antialias_cbmi, getOptions().isAntialiasScreen() );
820 customizeCheckBoxMenuItem( _background_gradient_cbmi, getOptions().isBackgroundColorGradient() );
821 customizeCheckBoxMenuItem( _show_domain_labels, getOptions().isShowDomainLabels() );
822 customizeCheckBoxMenuItem( _show_annotation_ref_source, getOptions().isShowAnnotationRefSource() );
823 customizeCheckBoxMenuItem( _abbreviate_scientific_names, getOptions().isAbbreviateScientificTaxonNames() );
824 customizeCheckBoxMenuItem( _show_default_node_shapes_external_cbmi, getOptions()
825 .isShowDefaultNodeShapesExternal() );
826 customizeCheckBoxMenuItem( _show_default_node_shapes_internal_cbmi, getOptions()
827 .isShowDefaultNodeShapesInternal() );
828 customizeCheckBoxMenuItem( _show_default_node_shapes_for_marked_cbmi, getOptions()
829 .isShowDefaultNodeShapesForMarkedNodes() );
830 customizeJMenuItem( _cycle_node_shape_mi );
831 customizeJMenuItem( _cycle_node_fill_mi );
832 customizeJMenuItem( _choose_node_size_mi );
833 customizeCheckBoxMenuItem( _color_labels_same_as_parent_branch, getOptions().isColorLabelsSameAsParentBranch() );
834 customizeCheckBoxMenuItem( _search_case_senstive_cbmi, getOptions().isSearchCaseSensitive() );
835 customizeCheckBoxMenuItem( _show_scale_cbmi, getOptions().isShowScale() );
836 customizeRadioButtonMenuItem( _non_lined_up_cladograms_rbmi,
837 getOptions().getCladogramType() == CLADOGRAM_TYPE.NON_LINED_UP );
838 customizeRadioButtonMenuItem( _uniform_cladograms_rbmi,
839 getOptions().getCladogramType() == CLADOGRAM_TYPE.TOTAL_NODE_SUM_DEP );
840 customizeRadioButtonMenuItem( _ext_node_dependent_cladogram_rbmi,
841 getOptions().getCladogramType() == CLADOGRAM_TYPE.EXT_NODE_SUM_DEP );
842 customizeCheckBoxMenuItem( _show_overview_cbmi, getOptions().isShowOverview() );
845 customizeCheckBoxMenuItem( _search_with_regex_cbmi, getOptions().isSearchWithRegex() );
849 customizeCheckBoxMenuItem( _search_whole_words_only_cbmi, getOptions().isMatchWholeTermsOnly() );
850 customizeCheckBoxMenuItem( _inverse_search_result_cbmi, getOptions().isInverseSearchResult() );
851 customizeCheckBoxMenuItem( _show_confidence_stddev_cbmi, getOptions().isShowConfidenceStddev() );
852 customizeCheckBoxMenuItem( _line_up_renderable_data_cbmi, getOptions().isLineUpRendarableNodeData() );
853 customizeCheckBoxMenuItem( _right_line_up_domains_cbmi, getOptions().isRightLineUpDomains() );
854 _jmenubar.add( _options_jmenu );
857 void buildToolsMenu() {
858 _tools_menu = MainFrame.createMenu( "Tools", getConfiguration() );
859 _tools_menu.add( _confcolor_item = new JMenuItem( "Colorize Branches Depending on Confidence" ) );
860 customizeJMenuItem( _confcolor_item );
861 _tools_menu.add( _taxcolor_item = new JMenuItem( "Taxonomy Colorize Branches" ) );
862 customizeJMenuItem( _taxcolor_item );
863 _tools_menu.addSeparator();
864 _tools_menu.add( _remove_visual_styles_item = new JMenuItem( "Delete All Visual Styles From Nodes" ) );
865 _remove_visual_styles_item
866 .setToolTipText( "To remove all node visual styles (fonts, colors) from the current phylogeny." );
867 customizeJMenuItem( _remove_visual_styles_item );
868 _tools_menu.add( _remove_branch_color_item = new JMenuItem( "Delete All Colors From Branches" ) );
869 _remove_branch_color_item.setToolTipText( "To remove all branch color values from the current phylogeny." );
870 customizeJMenuItem( _remove_branch_color_item );
871 _tools_menu.addSeparator();
872 _tools_menu.add( _midpoint_root_item = new JMenuItem( "Midpoint-Root" ) );
873 customizeJMenuItem( _midpoint_root_item );
874 _tools_menu.addSeparator();
875 _tools_menu.add( _collapse_species_specific_subtrees = new JMenuItem( "Collapse Species-Specific Subtrees" ) );
876 customizeJMenuItem( _collapse_species_specific_subtrees );
877 _jmenubar.add( _tools_menu );
880 void buildTypeMenu() {
881 _type_menu = MainFrame.createMenu( MainFrame.TYPE_MENU_HEADER, getConfiguration() );
882 _type_menu.add( _rectangular_type_cbmi = new JCheckBoxMenuItem( MainFrame.RECTANGULAR_TYPE_CBMI_LABEL ) );
883 _type_menu.add( _euro_type_cbmi = new JCheckBoxMenuItem( MainFrame.EURO_TYPE_CBMI_LABEL ) );
884 _type_menu.add( _rounded_type_cbmi = new JCheckBoxMenuItem( MainFrame.ROUNDED_TYPE_CBMI_LABEL ) );
885 _type_menu.add( _curved_type_cbmi = new JCheckBoxMenuItem( MainFrame.CURVED_TYPE_CBMI_LABEL ) );
886 _type_menu.add( _triangular_type_cbmi = new JCheckBoxMenuItem( MainFrame.TRIANGULAR_TYPE_CBMI_LABEL ) );
887 _type_menu.add( _convex_type_cbmi = new JCheckBoxMenuItem( MainFrame.CONVEX_TYPE_CBMI_LABEL ) );
888 _type_menu.add( _unrooted_type_cbmi = new JCheckBoxMenuItem( MainFrame.UNROOTED_TYPE_CBMI_LABEL ) );
889 _type_menu.add( _circular_type_cbmi = new JCheckBoxMenuItem( MainFrame.CIRCULAR_TYPE_CBMI_LABEL ) );
890 customizeCheckBoxMenuItem( _rectangular_type_cbmi, false );
891 customizeCheckBoxMenuItem( _triangular_type_cbmi, false );
892 customizeCheckBoxMenuItem( _euro_type_cbmi, false );
893 customizeCheckBoxMenuItem( _rounded_type_cbmi, false );
894 customizeCheckBoxMenuItem( _curved_type_cbmi, false );
895 customizeCheckBoxMenuItem( _convex_type_cbmi, false );
896 customizeCheckBoxMenuItem( _unrooted_type_cbmi, false );
897 customizeCheckBoxMenuItem( _circular_type_cbmi, false );
898 _unrooted_type_cbmi.setToolTipText( MainFrame.USE_MOUSEWHEEL_SHIFT_TO_ROTATE );
899 _circular_type_cbmi.setToolTipText( MainFrame.USE_MOUSEWHEEL_SHIFT_TO_ROTATE );
900 initializeTypeMenu( getOptions() );
901 _jmenubar.add( _type_menu );
904 void buildViewMenu() {
905 _view_jmenu = MainFrame.createMenu( "View", getConfiguration() );
907 .add( _display_basic_information_item = new JMenuItem( MainFrame.SHOW_BASIC_TREE_INFORMATION_LABEL ) );
908 _view_jmenu.addSeparator();
909 _view_jmenu.add( _view_as_XML_item = new JMenuItem( "as phyloXML" ) );
910 _view_jmenu.add( _view_as_NH_item = new JMenuItem( "as Newick" ) );
911 _view_jmenu.add( _view_as_nexus_item = new JMenuItem( "as Nexus" ) );
912 customizeJMenuItem( _display_basic_information_item );
913 customizeJMenuItem( _view_as_NH_item );
914 customizeJMenuItem( _view_as_XML_item );
915 customizeJMenuItem( _view_as_nexus_item );
916 _jmenubar.add( _view_jmenu );
919 void checkTextFrames() {
920 if ( _textframes.size() > 5 ) {
922 if ( _textframes.getFirst() != null ) {
923 _textframes.getFirst().removeMe();
926 _textframes.removeFirst();
929 catch ( final NoSuchElementException e ) {
935 void clearCurrentExternalNodesDataBuffer() {
936 getCurrentTreePanel().clearCurrentExternalNodesDataBuffer();
939 void customizeCheckBoxMenuItem( final JCheckBoxMenuItem item, final boolean is_selected ) {
940 if ( item != null ) {
941 item.setFont( MainFrame.menu_font );
942 if ( !getConfiguration().isUseNativeUI() ) {
943 item.setBackground( getConfiguration().getGuiMenuBackgroundColor() );
944 item.setForeground( getConfiguration().getGuiMenuTextColor() );
946 item.setSelected( is_selected );
947 item.addActionListener( this );
951 void customizeJMenuItem( final JMenuItem jmi ) {
952 jmi.setFont( MainFrame.menu_font );
953 if ( !getConfiguration().isUseNativeUI() ) {
954 jmi.setBackground( getConfiguration().getGuiMenuBackgroundColor() );
955 jmi.setForeground( getConfiguration().getGuiMenuTextColor() );
957 jmi.addActionListener( this );
960 void displayBasicInformation() {
961 if ( ( getMainPanel() != null ) && ( getMainPanel().getCurrentPhylogeny() != null )
962 && !getMainPanel().getCurrentPhylogeny().isEmpty() ) {
963 String title = "Basic Information";
964 if ( !ForesterUtil.isEmpty( getMainPanel().getCurrentPhylogeny().getName() ) ) {
965 title = title + " for \"" + _mainpanel.getCurrentPhylogeny().getName() + "\"";
967 showTextFrame( AptxUtil.createBasicInformation( getMainPanel().getCurrentPhylogeny(), null ), title );
972 if ( !isOKforSDI( false, true ) ) {
975 if ( !_mainpanel.getCurrentPhylogeny().isRooted() ) {
976 JOptionPane.showMessageDialog( this,
977 "Gene tree is not rooted.",
978 "Cannot execute GSDI",
979 JOptionPane.ERROR_MESSAGE );
982 final Phylogeny gene_tree = _mainpanel.getCurrentPhylogeny().copy();
983 gene_tree.setAllNodesToNotCollapse();
984 gene_tree.recalculateNumberOfExternalDescendants( false );
986 final Phylogeny species_tree = _species_tree.copy();
988 gsdi = new GSDI( gene_tree, species_tree, false, true, true, true );
990 catch ( final SDIException e ) {
991 JOptionPane.showMessageDialog( this,
992 e.getLocalizedMessage(),
994 JOptionPane.ERROR_MESSAGE );
997 catch ( final Exception e ) {
998 AptxUtil.unexpectedException( e );
1001 gene_tree.setRerootable( false );
1002 gene_tree.clearHashIdToNodeMap();
1003 gene_tree.recalculateNumberOfExternalDescendants( true );
1004 _mainpanel.addPhylogenyInNewTab( gene_tree, getConfiguration(), "gene tree", null );
1005 getMainPanel().getControlPanel().setShowEvents( true );
1007 final int selected = _mainpanel.getTabbedPane().getSelectedIndex();
1008 _mainpanel.addPhylogenyInNewTab( species_tree, getConfiguration(), "species tree", null );
1010 _mainpanel.getTabbedPane().setSelectedIndex( selected );
1012 _mainpanel.getCurrentTreePanel().setEdited( true );
1013 final int poly = PhylogenyMethods.countNumberOfPolytomies( species_tree );
1014 if ( gsdi.getStrippedExternalGeneTreeNodes().size() > 0 ) {
1015 JOptionPane.showMessageDialog( this,
1016 "Duplications: " + gsdi.getDuplicationsSum() + "\n"
1017 + "Potential duplications: "
1018 + gsdi.getSpeciationOrDuplicationEventsSum() + "\n"
1019 + "Speciations: " + gsdi.getSpeciationsSum() + "\n"
1020 + "Stripped gene tree nodes: "
1021 + gsdi.getStrippedExternalGeneTreeNodes().size() + "\n"
1022 + "Taxonomy linkage based on: " + gsdi.getTaxCompBase() + "\n"
1023 + "Number of polytomies in species tree used: " + poly + "\n",
1024 "GSDI successfully completed",
1025 JOptionPane.WARNING_MESSAGE );
1028 JOptionPane.showMessageDialog( this,
1029 "Duplications: " + gsdi.getDuplicationsSum() + "\n"
1030 + "Potential duplications: "
1031 + gsdi.getSpeciationOrDuplicationEventsSum() + "\n"
1032 + "Speciations: " + gsdi.getSpeciationsSum() + "\n"
1033 + "Stripped gene tree nodes: "
1034 + gsdi.getStrippedExternalGeneTreeNodes().size() + "\n"
1035 + "Taxonomy linkage based on: " + gsdi.getTaxCompBase() + "\n"
1036 + "Number of polytomies in species tree used: " + poly + "\n",
1037 "GSDI successfully completed",
1038 JOptionPane.INFORMATION_MESSAGE );
1042 void executeGSDIR() {
1043 if ( !isOKforSDI( false, false ) ) {
1046 final int p = PhylogenyMethods.countNumberOfPolytomies( _mainpanel.getCurrentPhylogeny() );
1048 && !( ( p == 1 ) && ( _mainpanel.getCurrentPhylogeny().getRoot().getNumberOfDescendants() == 3 ) ) ) {
1049 JOptionPane.showMessageDialog( this,
1050 "Gene tree is not completely binary",
1051 "Cannot execute GSDI",
1052 JOptionPane.ERROR_MESSAGE );
1055 final Phylogeny gene_tree = _mainpanel.getCurrentPhylogeny().copy();
1056 gene_tree.setAllNodesToNotCollapse();
1057 gene_tree.recalculateNumberOfExternalDescendants( false );
1059 final Phylogeny species_tree = _species_tree.copy();
1061 gsdir = new GSDIR( gene_tree, species_tree, true, true, true );
1063 catch ( final SDIException e ) {
1064 JOptionPane.showMessageDialog( this,
1065 e.getLocalizedMessage(),
1066 "Error during GSDIR",
1067 JOptionPane.ERROR_MESSAGE );
1070 catch ( final Exception e ) {
1071 AptxUtil.unexpectedException( e );
1074 final Phylogeny result_gene_tree = gsdir.getMinDuplicationsSumGeneTree();
1075 result_gene_tree.setRerootable( false );
1076 result_gene_tree.clearHashIdToNodeMap();
1077 result_gene_tree.recalculateNumberOfExternalDescendants( true );
1078 PhylogenyMethods.orderAppearance( result_gene_tree.getRoot(), true, true, DESCENDANT_SORT_PRIORITY.NODE_NAME );
1079 _mainpanel.addPhylogenyInNewTab( result_gene_tree, getConfiguration(), "gene tree", null );
1080 getMainPanel().getControlPanel().setShowEvents( true );
1082 final int selected = _mainpanel.getTabbedPane().getSelectedIndex();
1083 _mainpanel.addPhylogenyInNewTab( species_tree, getConfiguration(), "species tree", null );
1085 _mainpanel.getTabbedPane().setSelectedIndex( selected );
1087 _mainpanel.getCurrentTreePanel().setEdited( true );
1088 final int poly = PhylogenyMethods.countNumberOfPolytomies( species_tree );
1089 if ( gsdir.getStrippedExternalGeneTreeNodes().size() > 0 ) {
1090 JOptionPane.showMessageDialog( this,
1091 "Minimal duplications: " + gsdir.getMinDuplicationsSum() + "\n"
1092 + "Speciations: " + gsdir.getSpeciationsSum() + "\n"
1093 + "Stripped gene tree nodes: "
1094 + gsdir.getStrippedExternalGeneTreeNodes().size() + "\n"
1095 + "Taxonomy linkage based on: " + gsdir.getTaxCompBase() + "\n"
1096 + "Number of polytomies in species tree used: " + poly + "\n",
1097 "GSDIR successfully completed",
1098 JOptionPane.WARNING_MESSAGE );
1101 JOptionPane.showMessageDialog( this,
1102 "Minimal duplications: " + gsdir.getMinDuplicationsSum() + "\n"
1103 + "Speciations: " + gsdir.getSpeciationsSum() + "\n"
1104 + "Stripped gene tree nodes: "
1105 + gsdir.getStrippedExternalGeneTreeNodes().size() + "\n"
1106 + "Taxonomy linkage based on: " + gsdir.getTaxCompBase() + "\n"
1107 + "Number of polytomies in species tree used: " + poly + "\n",
1108 "GSDIR successfully completed",
1109 JOptionPane.INFORMATION_MESSAGE );
1113 Configuration getConfiguration() {
1114 return _configuration;
1117 TreePanel getCurrentTreePanel() {
1118 return getMainPanel().getCurrentTreePanel();
1121 JCheckBoxMenuItem getlabelDirectionCbmi() {
1122 return _label_direction_cbmi;
1125 Options getOtions() {
1129 void initializeTypeMenu( final Options options ) {
1130 setTypeMenuToAllUnselected();
1132 switch ( options.getPhylogenyGraphicsType() ) {
1134 _convex_type_cbmi.setSelected( true );
1137 _curved_type_cbmi.setSelected( true );
1140 _euro_type_cbmi.setSelected( true );
1143 _rounded_type_cbmi.setSelected( true );
1146 _triangular_type_cbmi.setSelected( true );
1149 _unrooted_type_cbmi.setSelected( true );
1152 _circular_type_cbmi.setSelected( true );
1155 _rectangular_type_cbmi.setSelected( true );
1159 catch ( final NullPointerException np ) {
1160 // In all likelihood, this is caused by menu-less display.
1164 boolean isOKforSDI( final boolean species_tree_has_to_binary, final boolean gene_tree_has_to_binary ) {
1165 if ( ( _mainpanel.getCurrentPhylogeny() == null ) || _mainpanel.getCurrentPhylogeny().isEmpty() ) {
1168 else if ( ( _species_tree == null ) || _species_tree.isEmpty() ) {
1169 JOptionPane.showMessageDialog( this,
1170 "No species tree loaded",
1171 "Cannot execute GSDI",
1172 JOptionPane.ERROR_MESSAGE );
1175 else if ( species_tree_has_to_binary && !_species_tree.isCompletelyBinary() ) {
1176 JOptionPane.showMessageDialog( this,
1177 "Species tree is not completely binary",
1178 "Cannot execute GSDI",
1179 JOptionPane.ERROR_MESSAGE );
1182 else if ( gene_tree_has_to_binary && !_mainpanel.getCurrentPhylogeny().isCompletelyBinary() ) {
1183 JOptionPane.showMessageDialog( this,
1184 "Gene tree is not completely binary",
1185 "Cannot execute GSDI",
1186 JOptionPane.ERROR_MESSAGE );
1194 boolean isSubtreeDisplayed() {
1195 if ( getCurrentTreePanel() != null ) {
1196 if ( getCurrentTreePanel().isCurrentTreeIsSubtree() ) {
1198 .showMessageDialog( this,
1199 "This operation can only be performed on a complete tree, not on the currently displayed sub-tree only.",
1200 "Operation can not be exectuted on a sub-tree",
1201 JOptionPane.WARNING_MESSAGE );
1208 void removeAllTextFrames() {
1209 for( final TextFrame tf : _textframes ) {
1214 _textframes.clear();
1217 void setConfiguration( final Configuration configuration ) {
1218 _configuration = configuration;
1221 void setOptions( final Options options ) {
1225 void setSelectedTypeInTypeMenu( final PHYLOGENY_GRAPHICS_TYPE type ) {
1226 setTypeMenuToAllUnselected();
1230 _circular_type_cbmi.setSelected( true );
1233 _convex_type_cbmi.setSelected( true );
1236 _curved_type_cbmi.setSelected( true );
1239 _euro_type_cbmi.setSelected( true );
1242 _rounded_type_cbmi.setSelected( true );
1245 _rectangular_type_cbmi.setSelected( true );
1248 _triangular_type_cbmi.setSelected( true );
1251 _unrooted_type_cbmi.setSelected( true );
1254 throw new IllegalArgumentException( "unknown type: " + type );
1257 catch ( final NullPointerException np ) {
1258 // In all likelihood, this is caused by menu-less display.
1262 void setTypeMenuToAllUnselected() {
1263 if ( _convex_type_cbmi != null ) {
1264 _convex_type_cbmi.setSelected( false );
1266 if ( _curved_type_cbmi != null ) {
1267 _curved_type_cbmi.setSelected( false );
1269 if ( _euro_type_cbmi != null ) {
1270 _euro_type_cbmi.setSelected( false );
1272 if ( _rounded_type_cbmi != null ) {
1273 _rounded_type_cbmi.setSelected( false );
1275 if ( _triangular_type_cbmi != null ) {
1276 _triangular_type_cbmi.setSelected( false );
1278 if ( _rectangular_type_cbmi != null ) {
1279 _rectangular_type_cbmi.setSelected( false );
1281 if ( _unrooted_type_cbmi != null ) {
1282 _unrooted_type_cbmi.setSelected( false );
1284 if ( _circular_type_cbmi != null ) {
1285 _circular_type_cbmi.setSelected( false );
1290 _mainpanel.getControlPanel().showWhole();
1293 void switchColors() {
1294 final TreeColorSet colorset = getMainPanel().getCurrentTreePanel().getTreeColorSet();
1295 final ColorSchemeChooser csc = new ColorSchemeChooser( getMainPanel(), colorset );
1296 csc.setVisible( true );
1297 getMainPanel().setTreeColorSet( colorset );
1300 void typeChanged( final Object o ) {
1301 updateTypeCheckboxes( getOptions(), o );
1302 updateOptions( getOptions() );
1303 if ( getCurrentTreePanel() != null ) {
1304 final PHYLOGENY_GRAPHICS_TYPE previous_type = getCurrentTreePanel().getPhylogenyGraphicsType();
1305 final PHYLOGENY_GRAPHICS_TYPE new_type = getOptions().getPhylogenyGraphicsType();
1306 if ( ( ( previous_type == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) && ( new_type != PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) )
1307 || ( ( previous_type == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) && ( new_type != PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) )
1308 || ( ( previous_type != PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) && ( new_type == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) )
1309 || ( ( previous_type != PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) && ( new_type == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) ) ) {
1310 getCurrentTreePanel().getControlPanel().showWhole();
1312 if ( getCurrentTreePanel().isPhyHasBranchLengths() && ( new_type != PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) ) {
1313 getCurrentTreePanel().getControlPanel().setDrawPhylogramEnabled( true );
1316 getCurrentTreePanel().getControlPanel().setDrawPhylogramEnabled( false );
1318 getCurrentTreePanel().setPhylogenyGraphicsType( getOptions().getPhylogenyGraphicsType() );
1319 MainFrame.updateScreenTextAntialias( getMainPanel().getTreePanels() );
1323 void updateOptions( final Options options ) {
1324 options.setAntialiasScreen( ( _screen_antialias_cbmi != null ) && _screen_antialias_cbmi.isSelected() );
1325 options.setBackgroundColorGradient( ( _background_gradient_cbmi != null )
1326 && _background_gradient_cbmi.isSelected() );
1327 options.setShowDomainLabels( ( _show_domain_labels != null ) && _show_domain_labels.isSelected() );
1328 options.setShowAnnotationRefSource( ( _show_annotation_ref_source != null )
1329 && _show_annotation_ref_source.isSelected() );
1330 options.setAbbreviateScientificTaxonNames( ( _abbreviate_scientific_names != null )
1331 && _abbreviate_scientific_names.isSelected() );
1332 options.setColorLabelsSameAsParentBranch( ( _color_labels_same_as_parent_branch != null )
1333 && _color_labels_same_as_parent_branch.isSelected() );
1334 options.setShowDefaultNodeShapesInternal( ( _show_default_node_shapes_internal_cbmi != null )
1335 && _show_default_node_shapes_internal_cbmi.isSelected() );
1336 options.setShowDefaultNodeShapesExternal( ( _show_default_node_shapes_external_cbmi != null )
1337 && _show_default_node_shapes_external_cbmi.isSelected() );
1338 options.setShowDefaultNodeShapesForMarkedNodes( ( _show_default_node_shapes_for_marked_cbmi != null )
1339 && _show_default_node_shapes_for_marked_cbmi.isSelected() );
1340 if ( ( _non_lined_up_cladograms_rbmi != null ) && ( _non_lined_up_cladograms_rbmi.isSelected() ) ) {
1341 options.setCladogramType( CLADOGRAM_TYPE.NON_LINED_UP );
1343 else if ( ( _uniform_cladograms_rbmi != null ) && ( _uniform_cladograms_rbmi.isSelected() ) ) {
1344 options.setCladogramType( CLADOGRAM_TYPE.TOTAL_NODE_SUM_DEP );
1346 else if ( ( _ext_node_dependent_cladogram_rbmi != null ) && ( _ext_node_dependent_cladogram_rbmi.isSelected() ) ) {
1347 options.setCladogramType( CLADOGRAM_TYPE.EXT_NODE_SUM_DEP );
1349 options.setSearchCaseSensitive( ( _search_case_senstive_cbmi != null )
1350 && _search_case_senstive_cbmi.isSelected() );
1351 if ( ( _show_scale_cbmi != null ) && _show_scale_cbmi.isEnabled() ) {
1352 options.setShowScale( _show_scale_cbmi.isSelected() );
1354 if ( _label_direction_cbmi != null ) {
1355 if ( _label_direction_cbmi.isSelected() ) {
1356 options.setNodeLabelDirection( NODE_LABEL_DIRECTION.RADIAL );
1359 options.setNodeLabelDirection( NODE_LABEL_DIRECTION.HORIZONTAL );
1362 options.setShowOverview( ( _show_overview_cbmi != null ) && _show_overview_cbmi.isSelected() );
1363 options.setShowConfidenceStddev( ( _show_confidence_stddev_cbmi != null )
1364 && _show_confidence_stddev_cbmi.isSelected() );
1365 options.setMatchWholeTermsOnly( ( _search_whole_words_only_cbmi != null )
1366 && _search_whole_words_only_cbmi.isSelected() );
1367 options.setSearchWithRegex( ( _search_with_regex_cbmi != null )
1368 && _search_with_regex_cbmi.isSelected() );
1370 options.setInverseSearchResult( ( _inverse_search_result_cbmi != null )
1371 && _inverse_search_result_cbmi.isSelected() );
1372 if ( ( _rectangular_type_cbmi != null ) && _rectangular_type_cbmi.isSelected() ) {
1373 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR );
1375 else if ( ( _triangular_type_cbmi != null ) && _triangular_type_cbmi.isSelected() ) {
1376 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.TRIANGULAR );
1378 else if ( ( _curved_type_cbmi != null ) && _curved_type_cbmi.isSelected() ) {
1379 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CURVED );
1381 else if ( ( _convex_type_cbmi != null ) && _convex_type_cbmi.isSelected() ) {
1382 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CONVEX );
1384 else if ( ( _euro_type_cbmi != null ) && _euro_type_cbmi.isSelected() ) {
1385 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE );
1387 else if ( ( _rounded_type_cbmi != null ) && _rounded_type_cbmi.isSelected() ) {
1388 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.ROUNDED );
1390 else if ( ( _unrooted_type_cbmi != null ) && _unrooted_type_cbmi.isSelected() ) {
1391 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.UNROOTED );
1393 else if ( ( _circular_type_cbmi != null ) && _circular_type_cbmi.isSelected() ) {
1394 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CIRCULAR );
1396 if ( ( _color_by_taxonomic_group_cbmi != null ) && _color_by_taxonomic_group_cbmi.isEnabled() ) {
1397 options.setColorByTaxonomicGroup( _color_by_taxonomic_group_cbmi.isSelected() );
1399 if ( ( _right_line_up_domains_cbmi != null ) && _right_line_up_domains_cbmi.isEnabled() ) {
1400 options.setRightLineUpDomains( _right_line_up_domains_cbmi.isSelected() );
1402 if ( ( _line_up_renderable_data_cbmi != null ) && _line_up_renderable_data_cbmi.isEnabled() ) {
1403 options.setLineUpRendarableNodeData( _line_up_renderable_data_cbmi.isSelected() );
1407 void updateTypeCheckboxes( final Options options, final Object o ) {
1408 setTypeMenuToAllUnselected();
1409 ( ( JCheckBoxMenuItem ) o ).setSelected( true );
1412 void viewAsNexus() {
1413 if ( ( getMainPanel().getCurrentPhylogeny() != null ) && !getMainPanel().getCurrentPhylogeny().isEmpty() ) {
1414 String title = "Nexus";
1415 if ( !ForesterUtil.isEmpty( getMainPanel().getCurrentPhylogeny().getName() ) ) {
1416 title = "\"" + getMainPanel().getCurrentPhylogeny().getName() + "\" in " + title;
1418 showTextFrame( getMainPanel().getCurrentPhylogeny().toNexus( getOptions()
1419 .getNhConversionSupportValueStyle() ),
1425 if ( ( getMainPanel().getCurrentPhylogeny() != null ) && !getMainPanel().getCurrentPhylogeny().isEmpty() ) {
1426 String title = "New Hampshire";
1427 if ( !ForesterUtil.isEmpty( getMainPanel().getCurrentPhylogeny().getName() ) ) {
1428 title = "\"" + getMainPanel().getCurrentPhylogeny().getName() + "\" in " + title;
1430 showTextFrame( getMainPanel().getCurrentPhylogeny().toNewHampshire( getOptions()
1431 .getNhConversionSupportValueStyle() ),
1437 if ( ( getMainPanel().getCurrentPhylogeny() != null ) && !getMainPanel().getCurrentPhylogeny().isEmpty() ) {
1438 String title = "phyloXML";
1439 if ( !ForesterUtil.isEmpty( getMainPanel().getCurrentPhylogeny().getName() ) ) {
1440 title = "\"" + getMainPanel().getCurrentPhylogeny().getName() + "\" in " + title;
1442 showTextFrame( getMainPanel().getCurrentPhylogeny().toPhyloXML( 0 ), title );
1446 private void chooseFont() {
1447 final FontChooser fc = new FontChooser();
1448 fc.setFont( getMainPanel().getTreeFontSet().getLargeFont() );
1449 fc.showDialog( this, "Select the Base Font" );
1450 getMainPanel().getTreeFontSet().setBaseFont( fc.getFont() );
1453 private void chooseMinimalConfidence() {
1454 final String s = ( String ) JOptionPane
1455 .showInputDialog( this,
1456 "Please the minimum for confidence values to be displayed.\n" + "[current value: "
1457 + getOptions().getMinConfidenceValue() + "]\n",
1458 "Minimal Confidence Value",
1459 JOptionPane.QUESTION_MESSAGE,
1462 getOptions().getMinConfidenceValue() );
1463 if ( !ForesterUtil.isEmpty( s ) ) {
1464 boolean success = true;
1466 final String m_str = s.trim();
1467 if ( !ForesterUtil.isEmpty( m_str ) ) {
1469 m = Double.parseDouble( m_str );
1471 catch ( final Exception ex ) {
1478 if ( success && ( m >= 0.0 ) ) {
1479 getOptions().setMinConfidenceValue( m );
1484 private void customizeRadioButtonMenuItem( final JRadioButtonMenuItem item, final boolean is_selected ) {
1485 if ( item != null ) {
1486 item.setFont( MainFrame.menu_font );
1487 if ( !getConfiguration().isUseNativeUI() ) {
1488 item.setBackground( getConfiguration().getGuiMenuBackgroundColor() );
1489 item.setForeground( getConfiguration().getGuiMenuTextColor() );
1491 item.setSelected( is_selected );
1492 item.addActionListener( this );
1496 MainPanel getMainPanel() {
1500 private Phylogeny getSpeciesTree() {
1501 return _species_tree;
1504 private boolean isScreenAntialias() {
1508 private void removeBranchColors() {
1509 if ( getMainPanel().getCurrentPhylogeny() != null ) {
1510 AptxUtil.removeBranchColors( getMainPanel().getCurrentPhylogeny() );
1514 private void removeVisualStyles() {
1515 if ( getMainPanel().getCurrentPhylogeny() != null ) {
1516 AptxUtil.removeVisualStyles( getMainPanel().getCurrentPhylogeny() );
1520 private void setMainPanel( final MainPanelApplets main_panel ) {
1521 _mainpanel = main_panel;
1524 private void setSpeciesTree( final Phylogeny species_tree ) {
1525 _species_tree = species_tree;
1528 private void setupUI() {
1530 if ( getConfiguration().isUseNativeUI() ) {
1531 UIManager.setLookAndFeel( UIManager.getSystemLookAndFeelClassName() );
1534 UIManager.setLookAndFeel( UIManager.getCrossPlatformLookAndFeelClassName() );
1537 catch ( final UnsupportedLookAndFeelException e ) {
1538 AptxUtil.dieWithSystemError( "UnsupportedLookAndFeelException: " + e.toString() );
1540 catch ( final ClassNotFoundException e ) {
1541 AptxUtil.dieWithSystemError( "ClassNotFoundException: " + e.toString() );
1543 catch ( final InstantiationException e ) {
1544 AptxUtil.dieWithSystemError( "InstantiationException: " + e.toString() );
1546 catch ( final IllegalAccessException e ) {
1547 AptxUtil.dieWithSystemError( "IllegalAccessException: " + e.toString() );
1549 catch ( final Exception e ) {
1550 AptxUtil.dieWithSystemError( e.toString() );
1554 static void setupScreenTextAntialias( final List<TreePanel> treepanels, final boolean antialias ) {
1555 for( final TreePanel tree_panel : treepanels ) {
1556 tree_panel.setTextAntialias();