2 package org.forester.archaeopteryx;
4 import java.awt.BorderLayout;
5 import java.awt.Container;
6 import java.awt.event.ActionEvent;
7 import java.awt.event.ActionListener;
8 import java.awt.event.ComponentAdapter;
9 import java.awt.event.ComponentEvent;
10 import java.io.ByteArrayOutputStream;
12 import java.io.IOException;
14 import java.util.LinkedList;
15 import java.util.List;
16 import java.util.NoSuchElementException;
18 import javax.swing.ButtonGroup;
19 import javax.swing.JApplet;
20 import javax.swing.JCheckBoxMenuItem;
21 import javax.swing.JMenu;
22 import javax.swing.JMenuBar;
23 import javax.swing.JMenuItem;
24 import javax.swing.JOptionPane;
25 import javax.swing.JRadioButtonMenuItem;
26 import javax.swing.UIManager;
27 import javax.swing.UnsupportedLookAndFeelException;
28 import javax.swing.event.ChangeEvent;
29 import javax.swing.event.ChangeListener;
31 import org.apache.commons.codec.binary.Base64;
32 import org.forester.archaeopteryx.AptxUtil.GraphicsExportType;
33 import org.forester.archaeopteryx.Options.CLADOGRAM_TYPE;
34 import org.forester.archaeopteryx.Options.NODE_LABEL_DIRECTION;
35 import org.forester.archaeopteryx.Options.PHYLOGENY_GRAPHICS_TYPE;
36 import org.forester.io.parsers.nhx.NHXParser.TAXONOMY_EXTRACTION;
37 import org.forester.phylogeny.Phylogeny;
38 import org.forester.phylogeny.PhylogenyMethods;
39 import org.forester.phylogeny.PhylogenyMethods.DESCENDANT_SORT_PRIORITY;
40 import org.forester.phylogeny.data.SequenceRelation;
41 import org.forester.sdi.GSDI;
42 import org.forester.sdi.GSDIR;
43 import org.forester.sdi.SDIException;
44 import org.forester.util.ForesterConstants;
45 import org.forester.util.ForesterUtil;
48 // <applet archive="forester.jar"
49 // code="org.forester.archaeopteryx.ArchaeopteryxE.class"
50 // codebase="http://www.myserver.org/path/to/forester"
53 // alt="ArchaeopteryxE is not working on your system (requires at least Sun Java 1.5)!">
54 // <param name="url_of_tree_to_load"
55 // value="http://www.myserver.org/examples/data/apaf.xml">
56 // <param name="config_file"
57 // value="http://www.myserver.org/examples/config/config_file.txt">
59 public class ArchaeopteryxE extends JApplet implements ActionListener {
61 private final static String NAME = "ArchaeopteryxE";
62 private static final long serialVersionUID = -1220055577935759443L;
63 private Configuration _configuration;
64 private MainPanelApplets _mainpanel;
65 private JMenuBar _jmenubar;
66 private JMenu _options_jmenu;
67 private JMenu _font_size_menu;
68 private JMenuItem _super_tiny_fonts_mi;
69 private JMenuItem _tiny_fonts_mi;
70 private JMenuItem _small_fonts_mi;
71 private JMenuItem _medium_fonts_mi;
72 private JMenuItem _large_fonts_mi;
73 private JMenu _tools_menu;
74 private JMenuItem _taxcolor_item;
75 private JMenuItem _confcolor_item;
76 private JMenuItem _midpoint_root_item;
77 private JMenu _view_jmenu;
78 private JMenuItem _view_as_XML_item;
79 private JMenuItem _view_as_NH_item;
80 private JMenuItem _view_as_nexus_item;
81 private JMenuItem _display_basic_information_item;
82 private JMenu _type_menu;
83 private JCheckBoxMenuItem _rectangular_type_cbmi;
84 private JCheckBoxMenuItem _triangular_type_cbmi;
85 private JCheckBoxMenuItem _curved_type_cbmi;
86 private JCheckBoxMenuItem _convex_type_cbmi;
87 private JCheckBoxMenuItem _euro_type_cbmi;
88 private JCheckBoxMenuItem _rounded_type_cbmi;
89 private JCheckBoxMenuItem _unrooted_type_cbmi;
90 private JCheckBoxMenuItem _circular_type_cbmi;
91 private JMenuItem _help_item;
92 private JMenuItem _about_item;
93 private JMenu _help_jmenu;
94 private JMenuItem _website_item;
95 private JMenuItem _phyloxml_website_item;
96 private JMenuItem _phyloxml_ref_item;
97 private JMenuItem _aptx_ref_item;
98 private JMenuItem _remove_branch_color_item;
99 private JMenuItem _remove_visual_styles_item;
100 private JCheckBoxMenuItem _show_domain_labels;
101 private JCheckBoxMenuItem _show_annotation_ref_source;
102 private JCheckBoxMenuItem _color_labels_same_as_parent_branch;
103 private JCheckBoxMenuItem _abbreviate_scientific_names;
104 private JCheckBoxMenuItem _screen_antialias_cbmi;
105 private JCheckBoxMenuItem _background_gradient_cbmi;
106 private JCheckBoxMenuItem _color_by_taxonomic_group_cbmi;
107 private JRadioButtonMenuItem _non_lined_up_cladograms_rbmi;
108 private JRadioButtonMenuItem _uniform_cladograms_rbmi;
109 private JRadioButtonMenuItem _ext_node_dependent_cladogram_rbmi;
110 private Options _options;
111 private JMenuItem _choose_font_mi;
112 private JMenuItem _switch_colors_mi;
113 JCheckBoxMenuItem _label_direction_cbmi;
114 private JCheckBoxMenuItem _show_scale_cbmi;
115 private JCheckBoxMenuItem _search_case_senstive_cbmi;
116 private JCheckBoxMenuItem _search_whole_words_only_cbmi;
117 private JCheckBoxMenuItem _inverse_search_result_cbmi;
118 private JCheckBoxMenuItem _show_overview_cbmi;
119 private JMenuItem _choose_minimal_confidence_mi;
120 private JCheckBoxMenuItem _show_branch_length_values_cbmi;
121 private JMenuItem _collapse_species_specific_subtrees;
122 private JMenuItem _overview_placment_mi;
123 private ButtonGroup _radio_group_1;
124 private JCheckBoxMenuItem _show_default_node_shapes_internal_cbmi;
125 private JCheckBoxMenuItem _show_default_node_shapes_external_cbmi;
126 private JMenuItem _cycle_node_shape_mi;
127 private JMenuItem _cycle_node_fill_mi;
128 private JMenuItem _choose_node_size_mi;
129 private JCheckBoxMenuItem _show_confidence_stddev_cbmi;
130 private final LinkedList<TextFrame> _textframes = new LinkedList<TextFrame>();
131 private JMenu _analysis_menu;
132 private JMenuItem _gsdi_item;
133 private JMenuItem _gsdir_item;
134 private Phylogeny _species_tree;
135 private JCheckBoxMenuItem _right_line_up_domains_cbmi;
136 private JCheckBoxMenuItem _line_up_renderable_data_cbmi;
139 public void actionPerformed( final ActionEvent e ) {
140 final Object o = e.getSource();
141 if ( o == _midpoint_root_item ) {
142 getMainPanel().getCurrentTreePanel().midpointRoot();
144 else if ( o == _gsdi_item ) {
145 if ( isSubtreeDisplayed() ) {
150 else if ( o == _gsdir_item ) {
151 if ( isSubtreeDisplayed() ) {
156 else if ( o == _taxcolor_item ) {
157 getMainPanel().getCurrentTreePanel().taxColor();
159 else if ( o == _confcolor_item ) {
160 getMainPanel().getCurrentTreePanel().confColor();
162 else if ( o == _collapse_species_specific_subtrees ) {
163 if ( getCurrentTreePanel() != null ) {
164 getCurrentTreePanel().collapseSpeciesSpecificSubtrees();
167 else if ( o == _remove_branch_color_item ) {
168 removeBranchColors();
170 else if ( o == _remove_visual_styles_item ) {
171 removeVisualStyles();
173 else if ( o == _switch_colors_mi ) {
176 else if ( o == _display_basic_information_item ) {
177 displayBasicInformation();
179 else if ( o == _view_as_NH_item ) {
182 else if ( o == _view_as_XML_item ) {
185 else if ( o == _view_as_nexus_item ) {
188 else if ( o == _super_tiny_fonts_mi ) {
189 if ( getCurrentTreePanel() != null ) {
190 getCurrentTreePanel().setSuperTinyFonts();
191 getCurrentTreePanel().repaint();
194 else if ( o == _tiny_fonts_mi ) {
195 if ( getCurrentTreePanel() != null ) {
196 getCurrentTreePanel().setTinyFonts();
197 getCurrentTreePanel().repaint();
200 else if ( o == _small_fonts_mi ) {
201 if ( getCurrentTreePanel() != null ) {
202 getCurrentTreePanel().setSmallFonts();
203 getCurrentTreePanel().repaint();
206 else if ( o == _medium_fonts_mi ) {
207 if ( getCurrentTreePanel() != null ) {
208 getCurrentTreePanel().setMediumFonts();
209 getCurrentTreePanel().repaint();
212 else if ( o == _large_fonts_mi ) {
213 if ( getCurrentTreePanel() != null ) {
214 getCurrentTreePanel().setLargeFonts();
215 getCurrentTreePanel().repaint();
218 else if ( o == _choose_font_mi ) {
221 else if ( o == _choose_minimal_confidence_mi ) {
222 chooseMinimalConfidence();
224 else if ( o == _choose_node_size_mi ) {
225 MainFrame.chooseNodeSize( getOptions(), this );
227 else if ( o == _overview_placment_mi ) {
228 MainFrame.cycleOverview( getOptions(), getCurrentTreePanel() );
230 else if ( o == _cycle_node_fill_mi ) {
231 MainFrame.cycleNodeFill( getOptions(), getCurrentTreePanel() );
233 else if ( o == _cycle_node_shape_mi ) {
234 MainFrame.cycleNodeShape( getOptions(), getCurrentTreePanel() );
236 else if ( o == _non_lined_up_cladograms_rbmi ) {
237 updateOptions( getOptions() );
238 _mainpanel.getControlPanel().showWhole();
240 else if ( o == _uniform_cladograms_rbmi ) {
241 updateOptions( getOptions() );
242 _mainpanel.getControlPanel().showWhole();
244 else if ( o == _ext_node_dependent_cladogram_rbmi ) {
245 updateOptions( getOptions() );
246 _mainpanel.getControlPanel().showWhole();
248 else if ( o == _search_case_senstive_cbmi ) {
249 updateOptions( getOptions() );
250 getMainPanel().getControlPanel().search0();
251 getMainPanel().getControlPanel().search1();
253 else if ( o == _search_whole_words_only_cbmi ) {
254 updateOptions( getOptions() );
255 getMainPanel().getControlPanel().search0();
256 getMainPanel().getControlPanel().search1();
258 else if ( o == _inverse_search_result_cbmi ) {
259 updateOptions( getOptions() );
260 getMainPanel().getControlPanel().search0();
261 getMainPanel().getControlPanel().search1();
263 else if ( o == _show_scale_cbmi ) {
264 updateOptions( getOptions() );
266 else if ( o == _show_branch_length_values_cbmi ) {
267 updateOptions( getOptions() );
269 else if ( o == _show_confidence_stddev_cbmi ) {
270 updateOptions( getOptions() );
272 else if ( o == _label_direction_cbmi ) {
273 updateOptions( getOptions() );
275 else if ( o == _abbreviate_scientific_names ) {
276 updateOptions( getOptions() );
278 else if ( o == _show_overview_cbmi ) {
279 updateOptions( getOptions() );
280 if ( getCurrentTreePanel() != null ) {
281 getCurrentTreePanel().updateOvSizes();
284 else if ( ( o == _rectangular_type_cbmi ) || ( o == _triangular_type_cbmi ) || ( o == _curved_type_cbmi )
285 || ( o == _convex_type_cbmi ) || ( o == _rounded_type_cbmi ) || ( o == _euro_type_cbmi )
286 || ( o == _unrooted_type_cbmi ) || ( o == _circular_type_cbmi ) ) {
289 else if ( o == _screen_antialias_cbmi ) {
290 updateOptions( getOptions() );
291 setupScreenTextAntialias( getMainPanel().getTreePanels(), isScreenAntialias() );
293 else if ( o == _background_gradient_cbmi ) {
294 updateOptions( getOptions() );
296 else if ( o == _show_domain_labels ) {
297 updateOptions( getOptions() );
299 else if ( o == _color_labels_same_as_parent_branch ) {
300 updateOptions( getOptions() );
302 else if ( o == _show_default_node_shapes_internal_cbmi ) {
303 updateOptions( getOptions() );
305 else if ( o == _show_default_node_shapes_external_cbmi ) {
306 updateOptions( getOptions() );
308 else if ( o == _about_item ) {
311 else if ( o == _help_item ) {
313 AptxUtil.openWebsite( Constants.APTX_DOC_SITE, true, this );
315 catch ( final IOException e1 ) {
316 ForesterUtil.printErrorMessage( Constants.PRG_NAME, e1.toString() );
319 else if ( o == _website_item ) {
321 AptxUtil.openWebsite( Constants.APTX_WEB_SITE, true, this );
323 catch ( final IOException e1 ) {
324 ForesterUtil.printErrorMessage( Constants.PRG_NAME, e1.toString() );
327 else if ( o == _phyloxml_website_item ) {
329 AptxUtil.openWebsite( Constants.PHYLOXML_WEB_SITE, true, this );
331 catch ( final IOException e1 ) {
332 ForesterUtil.printErrorMessage( Constants.PRG_NAME, e1.toString() );
335 else if ( o == _aptx_ref_item ) {
337 AptxUtil.openWebsite( Constants.APTX_REFERENCE_URL, true, this );
339 catch ( final IOException e1 ) {
340 ForesterUtil.printErrorMessage( Constants.PRG_NAME, e1.toString() );
343 else if ( o == _phyloxml_ref_item ) {
345 AptxUtil.openWebsite( Constants.PHYLOXML_REFERENCE_URL, true, this );
347 catch ( final IOException e1 ) {
348 ForesterUtil.printErrorMessage( Constants.PRG_NAME, e1.toString() );
351 else if ( o == _color_by_taxonomic_group_cbmi ) {
352 updateOptions( getOptions() );
354 else if ( o == _line_up_renderable_data_cbmi ) {
355 if ( !_line_up_renderable_data_cbmi.isSelected() ) {
356 _right_line_up_domains_cbmi.setSelected( false );
358 updateOptions( getOptions() );
360 else if ( o == _right_line_up_domains_cbmi ) {
361 if ( _right_line_up_domains_cbmi.isSelected() ) {
362 _line_up_renderable_data_cbmi.setSelected( true );
364 updateOptions( getOptions() );
370 public void destroy() {
371 AptxUtil.printAppletMessage( NAME, "going to be destroyed " );
372 removeAllTextFrames();
373 if ( getMainPanel() != null ) {
374 getMainPanel().terminate();
379 * This method returns the current external node data which
380 * has been selected by the user by clicking the "Return ..."
381 * menu item. This method is expected to be called from Javascript or
384 * @return current external node data as String
386 public String getCurrentExternalNodesDataBuffer() {
387 return getCurrentTreePanel().getCurrentExternalNodesDataBufferAsString();
390 public int getCurrentExternalNodesDataBufferChangeCounter() {
391 return getCurrentTreePanel().getCurrentExternalNodesDataBufferChangeCounter();
394 public int getCurrentExternalNodesDataBufferLength() {
395 return getCurrentTreePanel().getCurrentExternalNodesDataBufferAsString().length();
399 * This method returns the current phylogeny as a string in the chosen format
401 * @param format must be NH, NHX, NEXUS or PHYLOXML
402 * @return the phylogeny string
403 * @author Herve Menager
405 public String getCurrentPhylogeny( final String format ) {
406 removeAllTextFrames();
407 if ( ( getMainPanel().getCurrentPhylogeny() == null ) || getMainPanel().getCurrentPhylogeny().isEmpty()
408 || ( getMainPanel().getCurrentPhylogeny().getNumberOfExternalNodes() > 10000 ) ) {
411 switch ( ForesterConstants.PhylogeneticTreeFormats.valueOf( format ) ) {
413 return getMainPanel().getCurrentPhylogeny().toNewHampshire();
415 return getMainPanel().getCurrentPhylogeny().toNewHampshireX();
417 return getMainPanel().getCurrentPhylogeny().toNexus();
419 return getMainPanel().getCurrentPhylogeny().toPhyloXML( -1 );
427 * This method returns a view of the current phylogeny in a chosen
428 * graphics format, base64-encoded in a string so that in can be used
431 * @param format must be GraphicsExportType (gif, jpg, pdf, png, tif, bmp)
432 * @return the phylogeny string
433 * @author Herve Menager
435 public String getCurrentPhylogenyGraphicsAsBase64EncodedString( final String format ) {
436 final ByteArrayOutputStream baos = new ByteArrayOutputStream();
438 AptxUtil.writePhylogenyToGraphicsByteArrayOutputStream( baos,
439 _mainpanel.getWidth(),
440 _mainpanel.getHeight(),
441 getCurrentTreePanel(),
442 getCurrentTreePanel().getControlPanel(),
443 GraphicsExportType.valueOf( format ),
446 catch ( final IOException ioe ) {
447 ForesterUtil.printErrorMessage( NAME, ioe.toString() );
448 ioe.printStackTrace();
449 JOptionPane.showMessageDialog( this,
450 NAME + ": Failed to generate graphics: " + "\nException: " + ioe,
451 "Failed to generate graphics",
452 JOptionPane.ERROR_MESSAGE );
455 final byte[] bytes = baos.toByteArray();
456 final String dataImg = Base64.encodeBase64String( bytes );
460 public Options getOptions() {
466 final String config_filename = getParameter( Constants.APPLET_PARAM_NAME_FOR_CONFIG_FILE_URL );
467 AptxUtil.printAppletMessage( NAME, "URL for configuration file is: " + config_filename );
468 final Configuration configuration = new Configuration( config_filename, true, true, true );
469 setConfiguration( configuration );
470 setOptions( Options.createInstance( configuration ) );
472 final String tree_url_str = getParameter( Constants.APPLET_PARAM_NAME_FOR_URL_OF_TREE_TO_LOAD );
473 if ( ForesterUtil.isEmpty( tree_url_str ) ) {
474 ForesterUtil.printErrorMessage( NAME, "could not get tree URL from "
475 + Constants.APPLET_PARAM_NAME_FOR_URL_OF_TREE_TO_LOAD );
476 JOptionPane.showMessageDialog( this, NAME + ": could not get tree URL from "
477 + Constants.APPLET_PARAM_NAME_FOR_URL_OF_TREE_TO_LOAD, "Failed get URL", JOptionPane.ERROR_MESSAGE );
480 AptxUtil.printAppletMessage( NAME, "URL for phylogenies is " + tree_url_str );
481 // Get URL to tree file
484 phys_url = new URL( tree_url_str );
486 catch ( final Exception e ) {
487 ForesterUtil.printErrorMessage( NAME, "error: " + e );
489 JOptionPane.showMessageDialog( this, NAME + ": Could not create URL from: \"" + tree_url_str
490 + "\"\nException: " + e, "Failed to create URL", JOptionPane.ERROR_MESSAGE );
492 if ( phys_url == null ) {
493 ForesterUtil.printErrorMessage( NAME, "failed to get tree URL from "
494 + Constants.APPLET_PARAM_NAME_FOR_URL_OF_TREE_TO_LOAD );
495 JOptionPane.showMessageDialog( this,
496 NAME + ": Could not create URL from: \"" + tree_url_str,
497 "Failed to create URL",
498 JOptionPane.ERROR_MESSAGE );
501 // Load the tree from URL
502 Phylogeny[] phys = null;
504 phys = AptxUtil.readPhylogeniesFromUrl( phys_url,
505 getConfiguration().isValidatePhyloXmlAgainstSchema(),
506 getConfiguration().isReplaceUnderscoresInNhParsing(),
507 getConfiguration().isInternalNumberAreConfidenceForNhParsing(),
508 getConfiguration().getTaxonomyExtraction(),
509 getConfiguration().isMidpointReroot() );
511 catch ( final Exception e ) {
512 ForesterUtil.printErrorMessage( NAME, e.toString() );
514 JOptionPane.showMessageDialog( this,
515 NAME + ": Failed to read phylogenies: " + "\nException: " + e,
516 "Failed to read phylogenies",
517 JOptionPane.ERROR_MESSAGE );
519 if ( phys == null ) {
520 ForesterUtil.printErrorMessage( NAME, "phylogenies from [" + phys_url + "] are null" );
521 JOptionPane.showMessageDialog( this,
522 NAME + ": phylogenies from [" + phys_url + "] are null",
523 "Failed to read phylogenies",
524 JOptionPane.ERROR_MESSAGE );
527 else if ( phys.length < 1 ) {
528 ForesterUtil.printErrorMessage( NAME, "phylogenies from [" + phys_url + "] are empty" );
529 JOptionPane.showMessageDialog( this,
530 NAME + ": phylogenies from [" + phys_url + "] are empty",
531 "Failed to read phylogenies",
532 JOptionPane.ERROR_MESSAGE );
536 AptxUtil.printAppletMessage( NAME, "loaded " + phys.length + " phylogenies from: " + phys_url );
539 final String species_tree_url_str = getParameter( Constants.APPLET_PARAM_NAME_FOR_URL_OF_SPECIES_TREE_TO_LOAD );
540 if ( !ForesterUtil.isEmpty( species_tree_url_str ) ) {
541 AptxUtil.printAppletMessage( NAME, "URL of species tree to load: \"" + species_tree_url_str + "\"" );
542 Phylogeny[] species_trees = null;
544 final URL species_tree_url = new URL( species_tree_url_str );
545 species_trees = AptxUtil.readPhylogeniesFromUrl( species_tree_url,
546 configuration.isValidatePhyloXmlAgainstSchema(),
547 configuration.isReplaceUnderscoresInNhParsing(),
549 TAXONOMY_EXTRACTION.NO,
552 catch ( final IOException e ) {
553 ForesterUtil.printErrorMessage( NAME, "could not read species tree from [" + species_tree_url_str
555 JOptionPane.showMessageDialog( this, NAME + ": could not read species tree from ["
556 + species_tree_url_str + "]", "Failed to read species tree", JOptionPane.ERROR_MESSAGE );
558 if ( ( species_trees != null ) && ( species_trees.length > 0 ) ) {
559 AptxUtil.printAppletMessage( NAME, "successfully read species tree" );
560 if ( species_trees[ 0 ].isEmpty() ) {
561 ForesterUtil.printErrorMessage( NAME, "species tree is empty" );
563 else if ( !species_trees[ 0 ].isRooted() ) {
564 ForesterUtil.printErrorMessage( NAME, "species tree is not rooted" );
567 setSpeciesTree( species_trees[ 0 ] );
568 AptxUtil.printAppletMessage( NAME, "species tree OK" );
574 setMainPanel( new MainPanelApplets( getConfiguration(), this ) );
575 _jmenubar = new JMenuBar();
576 if ( !getConfiguration().isHideControlPanelAndMenubar() ) {
577 if ( !getConfiguration().isUseNativeUI() ) {
578 _jmenubar.setBackground( getConfiguration().getGuiMenuBackgroundColor() );
580 if ( getSpeciesTree() != null ) {
589 setJMenuBar( _jmenubar );
591 final Container contentpane = getContentPane();
592 contentpane.setLayout( new BorderLayout() );
593 contentpane.add( getMainPanel(), BorderLayout.CENTER );
594 addComponentListener( new ComponentAdapter() {
597 public void componentResized( final ComponentEvent e ) {
598 if ( getMainPanel().getCurrentTreePanel() != null ) {
599 getMainPanel().getCurrentTreePanel().calcParametersForPainting( getMainPanel()
600 .getCurrentTreePanel()
603 .getCurrentTreePanel()
606 .isAllowFontSizeChange() );
610 if ( getConfiguration().isUseTabbedDisplay() ) {
612 AptxUtil.printAppletMessage( NAME, "using tabbed display" );
613 AptxUtil.addPhylogeniesToTabs( phys,
614 new File( phys_url.getFile() ).getName(),
619 catch ( final Exception e ) {
620 ForesterUtil.printErrorMessage( NAME, e.toString() );
625 AptxUtil.printAppletMessage( NAME, "not using tabbed display" );
626 if ( getSpeciesTree() != null ) {
627 AptxUtil.printAppletMessage( NAME,
628 "Warning: gsdi (gene duplication inference) only available tabbed display" );
630 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 );
763 _options_jmenu.add( _show_overview_cbmi = new JCheckBoxMenuItem( MainFrame.SHOW_OVERVIEW_LABEL ) );
764 _options_jmenu.add( _show_scale_cbmi = new JCheckBoxMenuItem( MainFrame.DISPLAY_SCALE_LABEL ) );
766 .add( _show_branch_length_values_cbmi = new JCheckBoxMenuItem( MainFrame.DISPLAY_BRANCH_LENGTH_VALUES_LABEL ) );
768 .add( _show_default_node_shapes_internal_cbmi = new JCheckBoxMenuItem( MainFrame.DISPLAY_NODE_BOXES_LABEL_INT ) );
770 .add( _show_default_node_shapes_external_cbmi = new JCheckBoxMenuItem( MainFrame.DISPLAY_NODE_BOXES_LABEL_EXT ) );
771 if ( getConfiguration().doDisplayOption( Configuration.show_domain_architectures ) ) {
772 _options_jmenu.add( _show_domain_labels = new JCheckBoxMenuItem( MainFrame.SHOW_DOMAIN_LABELS_LABEL ) );
773 _options_jmenu.add( _right_line_up_domains_cbmi = new JCheckBoxMenuItem( MainFrame.RIGHT_LINE_UP_DOMAINS ) );
775 _options_jmenu.add( _line_up_renderable_data_cbmi = new JCheckBoxMenuItem( MainFrame.LINE_UP_RENDERABLE_DATA ) );
776 _options_jmenu.add( _show_annotation_ref_source = new JCheckBoxMenuItem( MainFrame.SHOW_ANN_REF_SOURCE_LABEL ) );
777 _options_jmenu.add( _show_confidence_stddev_cbmi = new JCheckBoxMenuItem( MainFrame.SHOW_CONF_STDDEV_LABEL ) );
779 .add( _color_by_taxonomic_group_cbmi = new JCheckBoxMenuItem( MainFrame.COLOR_BY_TAXONOMIC_GROUP ) );
781 .add( _color_labels_same_as_parent_branch = new JCheckBoxMenuItem( MainFrame.COLOR_LABELS_LABEL ) );
782 _color_labels_same_as_parent_branch.setToolTipText( MainFrame.COLOR_LABELS_TIP );
783 _options_jmenu.add( _abbreviate_scientific_names = new JCheckBoxMenuItem( MainFrame.ABBREV_SN_LABEL ) );
784 _options_jmenu.add( _label_direction_cbmi = new JCheckBoxMenuItem( MainFrame.LABEL_DIRECTION_LABEL ) );
785 _label_direction_cbmi.setToolTipText( MainFrame.LABEL_DIRECTION_TIP );
786 _options_jmenu.add( _screen_antialias_cbmi = new JCheckBoxMenuItem( MainFrame.SCREEN_ANTIALIAS_LABEL ) );
787 _options_jmenu.add( _background_gradient_cbmi = new JCheckBoxMenuItem( MainFrame.BG_GRAD_LABEL ) );
788 _options_jmenu.add( _cycle_node_shape_mi = new JMenuItem( MainFrame.CYCLE_NODE_SHAPE_LABEL ) );
789 _options_jmenu.add( _cycle_node_fill_mi = new JMenuItem( MainFrame.CYCLE_NODE_FILL_LABEL ) );
790 _options_jmenu.add( _choose_node_size_mi = new JMenuItem( MainFrame.CHOOSE_NODE_SIZE_LABEL ) );
791 _options_jmenu.add( _choose_minimal_confidence_mi = new JMenuItem( "" ) );
792 _options_jmenu.add( _overview_placment_mi = new JMenuItem( "" ) );
793 _options_jmenu.add( _switch_colors_mi = new JMenuItem( "" ) );
794 _options_jmenu.add( _choose_font_mi = new JMenuItem( "" ) );
796 _options_jmenu.addSeparator();
797 _options_jmenu.add( MainFrame.customizeMenuItemAsLabel( new JMenuItem( MainFrame.SEARCH_SUBHEADER ),
798 getConfiguration() ) );
800 .add( _search_case_senstive_cbmi = new JCheckBoxMenuItem( MainFrame.SEARCH_CASE_SENSITIVE_LABEL ) );
801 _options_jmenu.add( _search_whole_words_only_cbmi = new JCheckBoxMenuItem( MainFrame.SEARCH_TERMS_ONLY_LABEL ) );
803 .add( _inverse_search_result_cbmi = new JCheckBoxMenuItem( MainFrame.INVERSE_SEARCH_RESULT_LABEL ) );
804 customizeJMenuItem( _choose_font_mi );
805 customizeJMenuItem( _choose_minimal_confidence_mi );
806 customizeJMenuItem( _switch_colors_mi );
807 customizeJMenuItem( _overview_placment_mi );
808 customizeCheckBoxMenuItem( _color_by_taxonomic_group_cbmi, getOptions().isColorByTaxonomicGroup() );
809 customizeCheckBoxMenuItem( _label_direction_cbmi,
810 getOptions().getNodeLabelDirection() == NODE_LABEL_DIRECTION.RADIAL );
811 customizeCheckBoxMenuItem( _screen_antialias_cbmi, getOptions().isAntialiasScreen() );
812 customizeCheckBoxMenuItem( _background_gradient_cbmi, getOptions().isBackgroundColorGradient() );
813 customizeCheckBoxMenuItem( _show_domain_labels, getOptions().isShowDomainLabels() );
814 customizeCheckBoxMenuItem( _show_annotation_ref_source, getOptions().isShowAnnotationRefSource() );
815 customizeCheckBoxMenuItem( _abbreviate_scientific_names, getOptions().isAbbreviateScientificTaxonNames() );
816 customizeCheckBoxMenuItem( _show_default_node_shapes_external_cbmi, getOptions()
817 .isShowDefaultNodeShapesExternal() );
818 customizeCheckBoxMenuItem( _show_default_node_shapes_internal_cbmi, getOptions()
819 .isShowDefaultNodeShapesInternal() );
820 customizeJMenuItem( _cycle_node_shape_mi );
821 customizeJMenuItem( _cycle_node_fill_mi );
822 customizeJMenuItem( _choose_node_size_mi );
823 customizeCheckBoxMenuItem( _color_labels_same_as_parent_branch, getOptions().isColorLabelsSameAsParentBranch() );
824 customizeCheckBoxMenuItem( _search_case_senstive_cbmi, getOptions().isSearchCaseSensitive() );
825 customizeCheckBoxMenuItem( _show_scale_cbmi, getOptions().isShowScale() );
826 customizeRadioButtonMenuItem( _non_lined_up_cladograms_rbmi,
827 getOptions().getCladogramType() == CLADOGRAM_TYPE.NON_LINED_UP );
828 customizeRadioButtonMenuItem( _uniform_cladograms_rbmi,
829 getOptions().getCladogramType() == CLADOGRAM_TYPE.TOTAL_NODE_SUM_DEP );
830 customizeRadioButtonMenuItem( _ext_node_dependent_cladogram_rbmi,
831 getOptions().getCladogramType() == CLADOGRAM_TYPE.EXT_NODE_SUM_DEP );
832 customizeCheckBoxMenuItem( _show_branch_length_values_cbmi, getOptions().isShowBranchLengthValues() );
833 customizeCheckBoxMenuItem( _show_overview_cbmi, getOptions().isShowOverview() );
834 customizeCheckBoxMenuItem( _search_whole_words_only_cbmi, getOptions().isMatchWholeTermsOnly() );
835 customizeCheckBoxMenuItem( _inverse_search_result_cbmi, getOptions().isInverseSearchResult() );
836 customizeCheckBoxMenuItem( _show_confidence_stddev_cbmi, getOptions().isShowConfidenceStddev() );
837 customizeCheckBoxMenuItem( _line_up_renderable_data_cbmi, getOptions().isLineUpRendarableNodeData() );
838 customizeCheckBoxMenuItem( _right_line_up_domains_cbmi, getOptions().isRightLineUpDomains() );
839 _jmenubar.add( _options_jmenu );
842 void buildToolsMenu() {
843 _tools_menu = MainFrame.createMenu( "Tools", getConfiguration() );
844 _tools_menu.add( _confcolor_item = new JMenuItem( "Colorize Branches Depending on Confidence" ) );
845 customizeJMenuItem( _confcolor_item );
846 _tools_menu.add( _taxcolor_item = new JMenuItem( "Taxonomy Colorize Branches" ) );
847 customizeJMenuItem( _taxcolor_item );
848 _tools_menu.addSeparator();
849 _tools_menu.add( _remove_visual_styles_item = new JMenuItem( "Delete All Visual Styles From Nodes" ) );
850 _remove_visual_styles_item
851 .setToolTipText( "To remove all node visual styles (fonts, colors) from the current phylogeny." );
852 customizeJMenuItem( _remove_visual_styles_item );
853 _tools_menu.add( _remove_branch_color_item = new JMenuItem( "Delete All Colors From Branches" ) );
854 _remove_branch_color_item.setToolTipText( "To remove all branch color values from the current phylogeny." );
855 customizeJMenuItem( _remove_branch_color_item );
856 _tools_menu.addSeparator();
857 _tools_menu.add( _midpoint_root_item = new JMenuItem( "Midpoint-Root" ) );
858 customizeJMenuItem( _midpoint_root_item );
859 _tools_menu.addSeparator();
860 _tools_menu.add( _collapse_species_specific_subtrees = new JMenuItem( "Collapse Species-Specific Subtrees" ) );
861 customizeJMenuItem( _collapse_species_specific_subtrees );
862 _jmenubar.add( _tools_menu );
865 void buildTypeMenu() {
866 _type_menu = MainFrame.createMenu( MainFrame.TYPE_MENU_HEADER, getConfiguration() );
867 _type_menu.add( _rectangular_type_cbmi = new JCheckBoxMenuItem( MainFrame.RECTANGULAR_TYPE_CBMI_LABEL ) );
868 _type_menu.add( _euro_type_cbmi = new JCheckBoxMenuItem( MainFrame.EURO_TYPE_CBMI_LABEL ) );
869 _type_menu.add( _rounded_type_cbmi = new JCheckBoxMenuItem( MainFrame.ROUNDED_TYPE_CBMI_LABEL ) );
870 _type_menu.add( _curved_type_cbmi = new JCheckBoxMenuItem( MainFrame.CURVED_TYPE_CBMI_LABEL ) );
871 _type_menu.add( _triangular_type_cbmi = new JCheckBoxMenuItem( MainFrame.TRIANGULAR_TYPE_CBMI_LABEL ) );
872 _type_menu.add( _convex_type_cbmi = new JCheckBoxMenuItem( MainFrame.CONVEX_TYPE_CBMI_LABEL ) );
873 _type_menu.add( _unrooted_type_cbmi = new JCheckBoxMenuItem( MainFrame.UNROOTED_TYPE_CBMI_LABEL ) );
874 _type_menu.add( _circular_type_cbmi = new JCheckBoxMenuItem( MainFrame.CIRCULAR_TYPE_CBMI_LABEL ) );
875 customizeCheckBoxMenuItem( _rectangular_type_cbmi, false );
876 customizeCheckBoxMenuItem( _triangular_type_cbmi, false );
877 customizeCheckBoxMenuItem( _euro_type_cbmi, false );
878 customizeCheckBoxMenuItem( _rounded_type_cbmi, false );
879 customizeCheckBoxMenuItem( _curved_type_cbmi, false );
880 customizeCheckBoxMenuItem( _convex_type_cbmi, false );
881 customizeCheckBoxMenuItem( _unrooted_type_cbmi, false );
882 customizeCheckBoxMenuItem( _circular_type_cbmi, false );
883 _unrooted_type_cbmi.setToolTipText( MainFrame.USE_MOUSEWHEEL_SHIFT_TO_ROTATE );
884 _circular_type_cbmi.setToolTipText( MainFrame.USE_MOUSEWHEEL_SHIFT_TO_ROTATE );
885 initializeTypeMenu( getOptions() );
886 _jmenubar.add( _type_menu );
889 void buildViewMenu() {
890 _view_jmenu = MainFrame.createMenu( "View", getConfiguration() );
892 .add( _display_basic_information_item = new JMenuItem( MainFrame.SHOW_BASIC_TREE_INFORMATION_LABEL ) );
893 _view_jmenu.addSeparator();
894 _view_jmenu.add( _view_as_XML_item = new JMenuItem( "as phyloXML" ) );
895 _view_jmenu.add( _view_as_NH_item = new JMenuItem( "as Newick" ) );
896 _view_jmenu.add( _view_as_nexus_item = new JMenuItem( "as Nexus" ) );
897 customizeJMenuItem( _display_basic_information_item );
898 customizeJMenuItem( _view_as_NH_item );
899 customizeJMenuItem( _view_as_XML_item );
900 customizeJMenuItem( _view_as_nexus_item );
901 _jmenubar.add( _view_jmenu );
904 void checkTextFrames() {
905 if ( _textframes.size() > 5 ) {
907 if ( _textframes.getFirst() != null ) {
908 _textframes.getFirst().removeMe();
911 _textframes.removeFirst();
914 catch ( final NoSuchElementException e ) {
920 void clearCurrentExternalNodesDataBuffer() {
921 getCurrentTreePanel().clearCurrentExternalNodesDataBuffer();
924 void customizeCheckBoxMenuItem( final JCheckBoxMenuItem item, final boolean is_selected ) {
925 if ( item != null ) {
926 item.setFont( MainFrame.menu_font );
927 if ( !getConfiguration().isUseNativeUI() ) {
928 item.setBackground( getConfiguration().getGuiMenuBackgroundColor() );
929 item.setForeground( getConfiguration().getGuiMenuTextColor() );
931 item.setSelected( is_selected );
932 item.addActionListener( this );
936 void customizeJMenuItem( final JMenuItem jmi ) {
937 jmi.setFont( MainFrame.menu_font );
938 if ( !getConfiguration().isUseNativeUI() ) {
939 jmi.setBackground( getConfiguration().getGuiMenuBackgroundColor() );
940 jmi.setForeground( getConfiguration().getGuiMenuTextColor() );
942 jmi.addActionListener( this );
945 void displayBasicInformation() {
946 if ( ( getMainPanel().getCurrentPhylogeny() != null ) && !getMainPanel().getCurrentPhylogeny().isEmpty() ) {
947 String title = "Basic Information";
948 if ( !ForesterUtil.isEmpty( getMainPanel().getCurrentPhylogeny().getName() ) ) {
949 title = title + " for \"" + _mainpanel.getCurrentPhylogeny().getName() + "\"";
951 showTextFrame( AptxUtil.createBasicInformation( getMainPanel().getCurrentPhylogeny(), null ), title );
956 if ( !isOKforSDI( false, true ) ) {
959 if ( !_mainpanel.getCurrentPhylogeny().isRooted() ) {
960 JOptionPane.showMessageDialog( this,
961 "Gene tree is not rooted.",
962 "Cannot execute GSDI",
963 JOptionPane.ERROR_MESSAGE );
966 final Phylogeny gene_tree = _mainpanel.getCurrentPhylogeny().copy();
967 gene_tree.setAllNodesToNotCollapse();
968 gene_tree.recalculateNumberOfExternalDescendants( false );
970 final Phylogeny species_tree = _species_tree.copy();
972 gsdi = new GSDI( gene_tree, species_tree, false, true, true, true );
974 catch ( final SDIException e ) {
975 JOptionPane.showMessageDialog( this,
976 e.getLocalizedMessage(),
978 JOptionPane.ERROR_MESSAGE );
981 catch ( final Exception e ) {
982 AptxUtil.unexpectedException( e );
985 gene_tree.setRerootable( false );
986 gene_tree.clearHashIdToNodeMap();
987 gene_tree.recalculateNumberOfExternalDescendants( true );
988 _mainpanel.addPhylogenyInNewTab( gene_tree, getConfiguration(), "gene tree", null );
989 getMainPanel().getControlPanel().setShowEvents( true );
991 final int selected = _mainpanel.getTabbedPane().getSelectedIndex();
992 _mainpanel.addPhylogenyInNewTab( species_tree, getConfiguration(), "species tree", null );
994 _mainpanel.getTabbedPane().setSelectedIndex( selected );
996 _mainpanel.getCurrentTreePanel().setEdited( true );
997 final int poly = PhylogenyMethods.countNumberOfPolytomies( species_tree );
998 if ( gsdi.getStrippedExternalGeneTreeNodes().size() > 0 ) {
999 JOptionPane.showMessageDialog( this,
1000 "Duplications: " + gsdi.getDuplicationsSum() + "\n"
1001 + "Potential duplications: "
1002 + gsdi.getSpeciationOrDuplicationEventsSum() + "\n"
1003 + "Speciations: " + gsdi.getSpeciationsSum() + "\n"
1004 + "Stripped gene tree nodes: "
1005 + gsdi.getStrippedExternalGeneTreeNodes().size() + "\n"
1006 + "Taxonomy linkage based on: " + gsdi.getTaxCompBase() + "\n"
1007 + "Number of polytomies in species tree used: " + poly + "\n",
1008 "GSDI successfully completed",
1009 JOptionPane.WARNING_MESSAGE );
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.INFORMATION_MESSAGE );
1026 void executeGSDIR() {
1027 if ( !isOKforSDI( false, false ) ) {
1030 final int p = PhylogenyMethods.countNumberOfPolytomies( _mainpanel.getCurrentPhylogeny() );
1032 && !( ( p == 1 ) && ( _mainpanel.getCurrentPhylogeny().getRoot().getNumberOfDescendants() == 3 ) ) ) {
1033 JOptionPane.showMessageDialog( this,
1034 "Gene tree is not completely binary",
1035 "Cannot execute GSDI",
1036 JOptionPane.ERROR_MESSAGE );
1039 final Phylogeny gene_tree = _mainpanel.getCurrentPhylogeny().copy();
1040 gene_tree.setAllNodesToNotCollapse();
1041 gene_tree.recalculateNumberOfExternalDescendants( false );
1043 final Phylogeny species_tree = _species_tree.copy();
1045 gsdir = new GSDIR( gene_tree, species_tree, true, true, true );
1047 catch ( final SDIException e ) {
1048 JOptionPane.showMessageDialog( this,
1049 e.getLocalizedMessage(),
1050 "Error during GSDIR",
1051 JOptionPane.ERROR_MESSAGE );
1054 catch ( final Exception e ) {
1055 AptxUtil.unexpectedException( e );
1058 final Phylogeny result_gene_tree = gsdir.getMinDuplicationsSumGeneTree();
1059 result_gene_tree.setRerootable( false );
1060 result_gene_tree.clearHashIdToNodeMap();
1061 result_gene_tree.recalculateNumberOfExternalDescendants( true );
1062 PhylogenyMethods.orderAppearance( result_gene_tree.getRoot(), true, true, DESCENDANT_SORT_PRIORITY.NODE_NAME );
1063 _mainpanel.addPhylogenyInNewTab( result_gene_tree, getConfiguration(), "gene tree", null );
1064 getMainPanel().getControlPanel().setShowEvents( true );
1066 final int selected = _mainpanel.getTabbedPane().getSelectedIndex();
1067 _mainpanel.addPhylogenyInNewTab( species_tree, getConfiguration(), "species tree", null );
1069 _mainpanel.getTabbedPane().setSelectedIndex( selected );
1071 _mainpanel.getCurrentTreePanel().setEdited( true );
1072 final int poly = PhylogenyMethods.countNumberOfPolytomies( species_tree );
1073 if ( gsdir.getStrippedExternalGeneTreeNodes().size() > 0 ) {
1074 JOptionPane.showMessageDialog( this,
1075 "Minimal duplications: " + gsdir.getMinDuplicationsSum() + "\n"
1076 + "Speciations: " + gsdir.getSpeciationsSum() + "\n"
1077 + "Stripped gene tree nodes: "
1078 + gsdir.getStrippedExternalGeneTreeNodes().size() + "\n"
1079 + "Taxonomy linkage based on: " + gsdir.getTaxCompBase() + "\n"
1080 + "Number of polytomies in species tree used: " + poly + "\n",
1081 "GSDIR successfully completed",
1082 JOptionPane.WARNING_MESSAGE );
1085 JOptionPane.showMessageDialog( this,
1086 "Minimal duplications: " + gsdir.getMinDuplicationsSum() + "\n"
1087 + "Speciations: " + gsdir.getSpeciationsSum() + "\n"
1088 + "Stripped gene tree nodes: "
1089 + gsdir.getStrippedExternalGeneTreeNodes().size() + "\n"
1090 + "Taxonomy linkage based on: " + gsdir.getTaxCompBase() + "\n"
1091 + "Number of polytomies in species tree used: " + poly + "\n",
1092 "GSDIR successfully completed",
1093 JOptionPane.INFORMATION_MESSAGE );
1097 Configuration getConfiguration() {
1098 return _configuration;
1101 TreePanel getCurrentTreePanel() {
1102 return getMainPanel().getCurrentTreePanel();
1105 JCheckBoxMenuItem getlabelDirectionCbmi() {
1106 return _label_direction_cbmi;
1109 Options getOtions() {
1113 void initializeTypeMenu( final Options options ) {
1114 setTypeMenuToAllUnselected();
1116 switch ( options.getPhylogenyGraphicsType() ) {
1118 _convex_type_cbmi.setSelected( true );
1121 _curved_type_cbmi.setSelected( true );
1124 _euro_type_cbmi.setSelected( true );
1127 _rounded_type_cbmi.setSelected( true );
1130 _triangular_type_cbmi.setSelected( true );
1133 _unrooted_type_cbmi.setSelected( true );
1136 _circular_type_cbmi.setSelected( true );
1139 _rectangular_type_cbmi.setSelected( true );
1143 catch ( final NullPointerException np ) {
1144 // In all likelihood, this is caused by menu-less display.
1148 boolean isOKforSDI( final boolean species_tree_has_to_binary, final boolean gene_tree_has_to_binary ) {
1149 if ( ( _mainpanel.getCurrentPhylogeny() == null ) || _mainpanel.getCurrentPhylogeny().isEmpty() ) {
1152 else if ( ( _species_tree == null ) || _species_tree.isEmpty() ) {
1153 JOptionPane.showMessageDialog( this,
1154 "No species tree loaded",
1155 "Cannot execute GSDI",
1156 JOptionPane.ERROR_MESSAGE );
1159 else if ( species_tree_has_to_binary && !_species_tree.isCompletelyBinary() ) {
1160 JOptionPane.showMessageDialog( this,
1161 "Species tree is not completely binary",
1162 "Cannot execute GSDI",
1163 JOptionPane.ERROR_MESSAGE );
1166 else if ( gene_tree_has_to_binary && !_mainpanel.getCurrentPhylogeny().isCompletelyBinary() ) {
1167 JOptionPane.showMessageDialog( this,
1168 "Gene tree is not completely binary",
1169 "Cannot execute GSDI",
1170 JOptionPane.ERROR_MESSAGE );
1178 boolean isSubtreeDisplayed() {
1179 if ( getCurrentTreePanel() != null ) {
1180 if ( getCurrentTreePanel().isCurrentTreeIsSubtree() ) {
1182 .showMessageDialog( this,
1183 "This operation can only be performed on a complete tree, not on the currently displayed sub-tree only.",
1184 "Operation can not be exectuted on a sub-tree",
1185 JOptionPane.WARNING_MESSAGE );
1192 void removeAllTextFrames() {
1193 for( final TextFrame tf : _textframes ) {
1198 _textframes.clear();
1201 void setConfiguration( final Configuration configuration ) {
1202 _configuration = configuration;
1205 void setOptions( final Options options ) {
1209 void setSelectedTypeInTypeMenu( final PHYLOGENY_GRAPHICS_TYPE type ) {
1210 setTypeMenuToAllUnselected();
1214 _circular_type_cbmi.setSelected( true );
1217 _convex_type_cbmi.setSelected( true );
1220 _curved_type_cbmi.setSelected( true );
1223 _euro_type_cbmi.setSelected( true );
1226 _rounded_type_cbmi.setSelected( true );
1229 _rectangular_type_cbmi.setSelected( true );
1232 _triangular_type_cbmi.setSelected( true );
1235 _unrooted_type_cbmi.setSelected( true );
1238 throw new IllegalArgumentException( "unknown type: " + type );
1241 catch ( final NullPointerException np ) {
1242 // In all likelihood, this is caused by menu-less display.
1246 void setTypeMenuToAllUnselected() {
1247 if ( _convex_type_cbmi != null ) {
1248 _convex_type_cbmi.setSelected( false );
1250 if ( _curved_type_cbmi != null ) {
1251 _curved_type_cbmi.setSelected( false );
1253 if ( _euro_type_cbmi != null ) {
1254 _euro_type_cbmi.setSelected( false );
1256 if ( _rounded_type_cbmi != null ) {
1257 _rounded_type_cbmi.setSelected( false );
1259 if ( _triangular_type_cbmi != null ) {
1260 _triangular_type_cbmi.setSelected( false );
1262 if ( _rectangular_type_cbmi != null ) {
1263 _rectangular_type_cbmi.setSelected( false );
1265 if ( _unrooted_type_cbmi != null ) {
1266 _unrooted_type_cbmi.setSelected( false );
1268 if ( _circular_type_cbmi != null ) {
1269 _circular_type_cbmi.setSelected( false );
1274 _mainpanel.getControlPanel().showWhole();
1277 void switchColors() {
1278 final TreeColorSet colorset = getMainPanel().getCurrentTreePanel().getTreeColorSet();
1279 final ColorSchemeChooser csc = new ColorSchemeChooser( getMainPanel(), colorset );
1280 csc.setVisible( true );
1281 getMainPanel().setTreeColorSet( colorset );
1284 void typeChanged( final Object o ) {
1285 updateTypeCheckboxes( getOptions(), o );
1286 updateOptions( getOptions() );
1287 if ( getCurrentTreePanel() != null ) {
1288 final PHYLOGENY_GRAPHICS_TYPE previous_type = getCurrentTreePanel().getPhylogenyGraphicsType();
1289 final PHYLOGENY_GRAPHICS_TYPE new_type = getOptions().getPhylogenyGraphicsType();
1290 if ( ( ( previous_type == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) && ( new_type != PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) )
1291 || ( ( previous_type == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) && ( new_type != PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) )
1292 || ( ( previous_type != PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) && ( new_type == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) )
1293 || ( ( previous_type != PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) && ( new_type == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) ) ) {
1294 getCurrentTreePanel().getControlPanel().showWhole();
1296 if ( getCurrentTreePanel().isPhyHasBranchLengths() && ( new_type != PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) ) {
1297 getCurrentTreePanel().getControlPanel().setDrawPhylogramEnabled( true );
1300 getCurrentTreePanel().getControlPanel().setDrawPhylogramEnabled( false );
1302 getCurrentTreePanel().setPhylogenyGraphicsType( getOptions().getPhylogenyGraphicsType() );
1303 MainFrame.updateScreenTextAntialias( getMainPanel().getTreePanels() );
1307 void updateOptions( final Options options ) {
1308 options.setAntialiasScreen( ( _screen_antialias_cbmi != null ) && _screen_antialias_cbmi.isSelected() );
1309 options.setBackgroundColorGradient( ( _background_gradient_cbmi != null )
1310 && _background_gradient_cbmi.isSelected() );
1311 options.setShowDomainLabels( ( _show_domain_labels != null ) && _show_domain_labels.isSelected() );
1312 options.setShowAnnotationRefSource( ( _show_annotation_ref_source != null )
1313 && _show_annotation_ref_source.isSelected() );
1314 options.setAbbreviateScientificTaxonNames( ( _abbreviate_scientific_names != null )
1315 && _abbreviate_scientific_names.isSelected() );
1316 options.setColorLabelsSameAsParentBranch( ( _color_labels_same_as_parent_branch != null )
1317 && _color_labels_same_as_parent_branch.isSelected() );
1318 options.setShowDefaultNodeShapesInternal( ( _show_default_node_shapes_internal_cbmi != null )
1319 && _show_default_node_shapes_internal_cbmi.isSelected() );
1320 options.setShowDefaultNodeShapesExternal( ( _show_default_node_shapes_external_cbmi != null )
1321 && _show_default_node_shapes_external_cbmi.isSelected() );
1322 if ( ( _non_lined_up_cladograms_rbmi != null ) && ( _non_lined_up_cladograms_rbmi.isSelected() ) ) {
1323 options.setCladogramType( CLADOGRAM_TYPE.NON_LINED_UP );
1325 else if ( ( _uniform_cladograms_rbmi != null ) && ( _uniform_cladograms_rbmi.isSelected() ) ) {
1326 options.setCladogramType( CLADOGRAM_TYPE.TOTAL_NODE_SUM_DEP );
1328 else if ( ( _ext_node_dependent_cladogram_rbmi != null ) && ( _ext_node_dependent_cladogram_rbmi.isSelected() ) ) {
1329 options.setCladogramType( CLADOGRAM_TYPE.EXT_NODE_SUM_DEP );
1331 options.setSearchCaseSensitive( ( _search_case_senstive_cbmi != null )
1332 && _search_case_senstive_cbmi.isSelected() );
1333 if ( ( _show_scale_cbmi != null ) && _show_scale_cbmi.isEnabled() ) {
1334 options.setShowScale( _show_scale_cbmi.isSelected() );
1336 if ( _label_direction_cbmi != null ) {
1337 if ( _label_direction_cbmi.isSelected() ) {
1338 options.setNodeLabelDirection( NODE_LABEL_DIRECTION.RADIAL );
1341 options.setNodeLabelDirection( NODE_LABEL_DIRECTION.HORIZONTAL );
1344 options.setShowOverview( ( _show_overview_cbmi != null ) && _show_overview_cbmi.isSelected() );
1345 options.setShowConfidenceStddev( ( _show_confidence_stddev_cbmi != null )
1346 && _show_confidence_stddev_cbmi.isSelected() );
1347 if ( ( _show_branch_length_values_cbmi != null ) && _show_branch_length_values_cbmi.isEnabled() ) {
1348 options.setShowBranchLengthValues( _show_branch_length_values_cbmi.isSelected() );
1350 options.setMatchWholeTermsOnly( ( _search_whole_words_only_cbmi != null )
1351 && _search_whole_words_only_cbmi.isSelected() );
1352 options.setInverseSearchResult( ( _inverse_search_result_cbmi != null )
1353 && _inverse_search_result_cbmi.isSelected() );
1354 if ( ( _rectangular_type_cbmi != null ) && _rectangular_type_cbmi.isSelected() ) {
1355 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR );
1357 else if ( ( _triangular_type_cbmi != null ) && _triangular_type_cbmi.isSelected() ) {
1358 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.TRIANGULAR );
1360 else if ( ( _curved_type_cbmi != null ) && _curved_type_cbmi.isSelected() ) {
1361 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CURVED );
1363 else if ( ( _convex_type_cbmi != null ) && _convex_type_cbmi.isSelected() ) {
1364 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CONVEX );
1366 else if ( ( _euro_type_cbmi != null ) && _euro_type_cbmi.isSelected() ) {
1367 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE );
1369 else if ( ( _rounded_type_cbmi != null ) && _rounded_type_cbmi.isSelected() ) {
1370 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.ROUNDED );
1372 else if ( ( _unrooted_type_cbmi != null ) && _unrooted_type_cbmi.isSelected() ) {
1373 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.UNROOTED );
1375 else if ( ( _circular_type_cbmi != null ) && _circular_type_cbmi.isSelected() ) {
1376 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CIRCULAR );
1378 if ( ( _color_by_taxonomic_group_cbmi != null ) && _color_by_taxonomic_group_cbmi.isEnabled() ) {
1379 options.setColorByTaxonomicGroup( _color_by_taxonomic_group_cbmi.isSelected() );
1381 if ( ( _right_line_up_domains_cbmi != null ) && _right_line_up_domains_cbmi.isEnabled() ) {
1382 options.setRightLineUpDomains( _right_line_up_domains_cbmi.isSelected() );
1384 if ( ( _line_up_renderable_data_cbmi != null ) && _line_up_renderable_data_cbmi.isEnabled() ) {
1385 options.setLineUpRendarableNodeData( _line_up_renderable_data_cbmi.isSelected() );
1389 void updateTypeCheckboxes( final Options options, final Object o ) {
1390 setTypeMenuToAllUnselected();
1391 ( ( JCheckBoxMenuItem ) o ).setSelected( true );
1394 void viewAsNexus() {
1395 if ( ( getMainPanel().getCurrentPhylogeny() != null ) && !getMainPanel().getCurrentPhylogeny().isEmpty() ) {
1396 String title = "Nexus";
1397 if ( !ForesterUtil.isEmpty( getMainPanel().getCurrentPhylogeny().getName() ) ) {
1398 title = "\"" + getMainPanel().getCurrentPhylogeny().getName() + "\" in " + title;
1400 showTextFrame( getMainPanel().getCurrentPhylogeny().toNexus( getOptions()
1401 .getNhConversionSupportValueStyle() ),
1407 if ( ( getMainPanel().getCurrentPhylogeny() != null ) && !getMainPanel().getCurrentPhylogeny().isEmpty() ) {
1408 String title = "New Hampshire";
1409 if ( !ForesterUtil.isEmpty( getMainPanel().getCurrentPhylogeny().getName() ) ) {
1410 title = "\"" + getMainPanel().getCurrentPhylogeny().getName() + "\" in " + title;
1412 showTextFrame( getMainPanel().getCurrentPhylogeny().toNewHampshire( getOptions()
1413 .getNhConversionSupportValueStyle() ),
1419 if ( ( getMainPanel().getCurrentPhylogeny() != null ) && !getMainPanel().getCurrentPhylogeny().isEmpty() ) {
1420 String title = "phyloXML";
1421 if ( !ForesterUtil.isEmpty( getMainPanel().getCurrentPhylogeny().getName() ) ) {
1422 title = "\"" + getMainPanel().getCurrentPhylogeny().getName() + "\" in " + title;
1424 showTextFrame( getMainPanel().getCurrentPhylogeny().toPhyloXML( 0 ), title );
1428 private void chooseFont() {
1429 final FontChooser fc = new FontChooser();
1430 fc.setFont( getMainPanel().getTreeFontSet().getLargeFont() );
1431 fc.showDialog( this, "Select the Base Font" );
1432 getMainPanel().getTreeFontSet().setBaseFont( fc.getFont() );
1435 private void chooseMinimalConfidence() {
1436 final String s = ( String ) JOptionPane
1437 .showInputDialog( this,
1438 "Please the minimum for confidence values to be displayed.\n" + "[current value: "
1439 + getOptions().getMinConfidenceValue() + "]\n",
1440 "Minimal Confidence Value",
1441 JOptionPane.QUESTION_MESSAGE,
1444 getOptions().getMinConfidenceValue() );
1445 if ( !ForesterUtil.isEmpty( s ) ) {
1446 boolean success = true;
1448 final String m_str = s.trim();
1449 if ( !ForesterUtil.isEmpty( m_str ) ) {
1451 m = Double.parseDouble( m_str );
1453 catch ( final Exception ex ) {
1460 if ( success && ( m >= 0.0 ) ) {
1461 getOptions().setMinConfidenceValue( m );
1466 private void customizeRadioButtonMenuItem( final JRadioButtonMenuItem item, final boolean is_selected ) {
1467 if ( item != null ) {
1468 item.setFont( MainFrame.menu_font );
1469 if ( !getConfiguration().isUseNativeUI() ) {
1470 item.setBackground( getConfiguration().getGuiMenuBackgroundColor() );
1471 item.setForeground( getConfiguration().getGuiMenuTextColor() );
1473 item.setSelected( is_selected );
1474 item.addActionListener( this );
1478 private MainPanel getMainPanel() {
1482 private Phylogeny getSpeciesTree() {
1483 return _species_tree;
1486 private boolean isScreenAntialias() {
1490 private void removeBranchColors() {
1491 if ( getMainPanel().getCurrentPhylogeny() != null ) {
1492 AptxUtil.removeBranchColors( getMainPanel().getCurrentPhylogeny() );
1496 private void removeVisualStyles() {
1497 if ( getMainPanel().getCurrentPhylogeny() != null ) {
1498 AptxUtil.removeVisualStyles( getMainPanel().getCurrentPhylogeny() );
1502 private void setMainPanel( final MainPanelApplets main_panel ) {
1503 _mainpanel = main_panel;
1506 private void setSpeciesTree( final Phylogeny species_tree ) {
1507 _species_tree = species_tree;
1510 private void setupUI() {
1512 if ( getConfiguration().isUseNativeUI() ) {
1513 UIManager.setLookAndFeel( UIManager.getSystemLookAndFeelClassName() );
1516 UIManager.setLookAndFeel( UIManager.getCrossPlatformLookAndFeelClassName() );
1519 catch ( final UnsupportedLookAndFeelException e ) {
1520 AptxUtil.dieWithSystemError( "UnsupportedLookAndFeelException: " + e.toString() );
1522 catch ( final ClassNotFoundException e ) {
1523 AptxUtil.dieWithSystemError( "ClassNotFoundException: " + e.toString() );
1525 catch ( final InstantiationException e ) {
1526 AptxUtil.dieWithSystemError( "InstantiationException: " + e.toString() );
1528 catch ( final IllegalAccessException e ) {
1529 AptxUtil.dieWithSystemError( "IllegalAccessException: " + e.toString() );
1531 catch ( final Exception e ) {
1532 AptxUtil.dieWithSystemError( e.toString() );
1536 static void setupScreenTextAntialias( final List<TreePanel> treepanels, final boolean antialias ) {
1537 for( final TreePanel tree_panel : treepanels ) {
1538 tree_panel.setTextAntialias();