2 package org.forester.archaeopteryx;
4 import java.awt.BorderLayout;
5 import java.awt.Container;
6 import java.awt.event.ActionEvent;
7 import java.awt.event.ActionListener;
8 import java.awt.event.ComponentAdapter;
9 import java.awt.event.ComponentEvent;
10 import java.io.ByteArrayOutputStream;
12 import java.io.IOException;
14 import java.util.LinkedList;
15 import java.util.List;
16 import java.util.NoSuchElementException;
18 import javax.swing.ButtonGroup;
19 import javax.swing.JApplet;
20 import javax.swing.JCheckBoxMenuItem;
21 import javax.swing.JMenu;
22 import javax.swing.JMenuBar;
23 import javax.swing.JMenuItem;
24 import javax.swing.JOptionPane;
25 import javax.swing.JRadioButtonMenuItem;
26 import javax.swing.UIManager;
27 import javax.swing.UnsupportedLookAndFeelException;
28 import javax.swing.event.ChangeEvent;
29 import javax.swing.event.ChangeListener;
31 import org.apache.commons.codec.binary.Base64;
32 import org.forester.archaeopteryx.AptxUtil.GraphicsExportType;
33 import org.forester.archaeopteryx.Options.CLADOGRAM_TYPE;
34 import org.forester.archaeopteryx.Options.NODE_LABEL_DIRECTION;
35 import org.forester.archaeopteryx.Options.PHYLOGENY_GRAPHICS_TYPE;
36 import org.forester.io.parsers.nhx.NHXParser.TAXONOMY_EXTRACTION;
37 import org.forester.phylogeny.Phylogeny;
38 import org.forester.phylogeny.PhylogenyMethods;
39 import org.forester.phylogeny.PhylogenyMethods.DESCENDANT_SORT_PRIORITY;
40 import org.forester.phylogeny.data.SequenceRelation;
41 import org.forester.sdi.GSDI;
42 import org.forester.sdi.GSDIR;
43 import org.forester.sdi.SDIException;
44 import org.forester.util.ForesterConstants;
45 import org.forester.util.ForesterUtil;
48 // <applet archive="forester.jar"
49 // code="org.forester.archaeopteryx.ArchaeopteryxE.class"
50 // codebase="http://www.myserver.org/path/to/forester"
53 // alt="ArchaeopteryxE is not working on your system (requires at least Sun Java 1.5)!">
54 // <param name="url_of_tree_to_load"
55 // value="http://www.myserver.org/examples/data/apaf.xml">
56 // <param name="config_file"
57 // value="http://www.myserver.org/examples/config/config_file.txt">
59 public class ArchaeopteryxE extends JApplet implements ActionListener {
61 private final static String NAME = "ArchaeopteryxE";
62 private static final long serialVersionUID = -1220055577935759443L;
63 private Configuration _configuration;
64 private MainPanelApplets _mainpanel;
65 private JMenuBar _jmenubar;
66 private JMenu _options_jmenu;
67 private JMenu _font_size_menu;
68 private JMenuItem _super_tiny_fonts_mi;
69 private JMenuItem _tiny_fonts_mi;
70 private JMenuItem _small_fonts_mi;
71 private JMenuItem _medium_fonts_mi;
72 private JMenuItem _large_fonts_mi;
73 private JMenu _tools_menu;
74 private JMenuItem _taxcolor_item;
75 private JMenuItem _confcolor_item;
76 private JMenuItem _midpoint_root_item;
77 private JMenu _view_jmenu;
78 private JMenuItem _view_as_XML_item;
79 private JMenuItem _view_as_NH_item;
80 private JMenuItem _view_as_nexus_item;
81 private JMenuItem _display_basic_information_item;
82 private JMenu _type_menu;
83 private JCheckBoxMenuItem _rectangular_type_cbmi;
84 private JCheckBoxMenuItem _triangular_type_cbmi;
85 private JCheckBoxMenuItem _curved_type_cbmi;
86 private JCheckBoxMenuItem _convex_type_cbmi;
87 private JCheckBoxMenuItem _euro_type_cbmi;
88 private JCheckBoxMenuItem _rounded_type_cbmi;
89 private JCheckBoxMenuItem _unrooted_type_cbmi;
90 private JCheckBoxMenuItem _circular_type_cbmi;
91 private JMenuItem _help_item;
92 private JMenuItem _about_item;
93 private JMenu _help_jmenu;
94 private JMenuItem _website_item;
95 private JMenuItem _phyloxml_website_item;
96 private JMenuItem _phyloxml_ref_item;
97 private JMenuItem _aptx_ref_item;
98 private JMenuItem _remove_branch_color_item;
99 private JMenuItem _remove_visual_styles_item;
100 private JCheckBoxMenuItem _show_domain_labels;
101 private JCheckBoxMenuItem _show_annotation_ref_source;
102 private JCheckBoxMenuItem _color_labels_same_as_parent_branch;
103 private JCheckBoxMenuItem _abbreviate_scientific_names;
104 private JCheckBoxMenuItem _screen_antialias_cbmi;
105 private JCheckBoxMenuItem _background_gradient_cbmi;
106 private JCheckBoxMenuItem _color_by_taxonomic_group_cbmi;
107 private JRadioButtonMenuItem _non_lined_up_cladograms_rbmi;
108 private JRadioButtonMenuItem _uniform_cladograms_rbmi;
109 private JRadioButtonMenuItem _ext_node_dependent_cladogram_rbmi;
110 private Options _options;
111 private JMenuItem _choose_font_mi;
112 private JMenuItem _switch_colors_mi;
113 JCheckBoxMenuItem _label_direction_cbmi;
114 private JCheckBoxMenuItem _show_scale_cbmi;
115 private JCheckBoxMenuItem _search_case_senstive_cbmi;
116 private JCheckBoxMenuItem _search_whole_words_only_cbmi;
117 private JCheckBoxMenuItem _inverse_search_result_cbmi;
118 private JCheckBoxMenuItem _show_overview_cbmi;
119 private JMenuItem _choose_minimal_confidence_mi;
120 private JMenuItem _collapse_species_specific_subtrees;
121 private JMenuItem _overview_placment_mi;
122 private ButtonGroup _radio_group_1;
123 private JCheckBoxMenuItem _show_default_node_shapes_internal_cbmi;
124 private JCheckBoxMenuItem _show_default_node_shapes_external_cbmi;
125 private JCheckBoxMenuItem _show_default_node_shapes_for_marked_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_confidence_stddev_cbmi ) {
267 updateOptions( getOptions() );
269 else if ( o == _label_direction_cbmi ) {
270 updateOptions( getOptions() );
272 else if ( o == _abbreviate_scientific_names ) {
273 updateOptions( getOptions() );
275 else if ( o == _show_overview_cbmi ) {
276 updateOptions( getOptions() );
277 if ( getCurrentTreePanel() != null ) {
278 getCurrentTreePanel().updateOvSizes();
281 else if ( ( o == _rectangular_type_cbmi ) || ( o == _triangular_type_cbmi ) || ( o == _curved_type_cbmi )
282 || ( o == _convex_type_cbmi ) || ( o == _rounded_type_cbmi ) || ( o == _euro_type_cbmi )
283 || ( o == _unrooted_type_cbmi ) || ( o == _circular_type_cbmi ) ) {
286 else if ( o == _screen_antialias_cbmi ) {
287 updateOptions( getOptions() );
288 setupScreenTextAntialias( getMainPanel().getTreePanels(), isScreenAntialias() );
290 else if ( o == _background_gradient_cbmi ) {
291 updateOptions( getOptions() );
293 else if ( o == _show_domain_labels ) {
294 updateOptions( getOptions() );
296 else if ( o == _color_labels_same_as_parent_branch ) {
297 updateOptions( getOptions() );
299 else if ( o == _show_default_node_shapes_internal_cbmi ) {
300 updateOptions( getOptions() );
302 else if ( o == _show_default_node_shapes_external_cbmi ) {
303 updateOptions( getOptions() );
305 else if ( o == _about_item ) {
308 else if ( o == _help_item ) {
310 AptxUtil.openWebsite( Constants.APTX_DOC_SITE, true, this );
312 catch ( final IOException e1 ) {
313 ForesterUtil.printErrorMessage( Constants.PRG_NAME, e1.toString() );
316 else if ( o == _website_item ) {
318 AptxUtil.openWebsite( Constants.APTX_WEB_SITE, true, this );
320 catch ( final IOException e1 ) {
321 ForesterUtil.printErrorMessage( Constants.PRG_NAME, e1.toString() );
324 else if ( o == _phyloxml_website_item ) {
326 AptxUtil.openWebsite( Constants.PHYLOXML_WEB_SITE, true, this );
328 catch ( final IOException e1 ) {
329 ForesterUtil.printErrorMessage( Constants.PRG_NAME, e1.toString() );
332 else if ( o == _aptx_ref_item ) {
334 AptxUtil.openWebsite( Constants.APTX_REFERENCE_URL, true, this );
336 catch ( final IOException e1 ) {
337 ForesterUtil.printErrorMessage( Constants.PRG_NAME, e1.toString() );
340 else if ( o == _phyloxml_ref_item ) {
342 AptxUtil.openWebsite( Constants.PHYLOXML_REFERENCE_URL, true, this );
344 catch ( final IOException e1 ) {
345 ForesterUtil.printErrorMessage( Constants.PRG_NAME, e1.toString() );
348 else if ( o == _color_by_taxonomic_group_cbmi ) {
349 updateOptions( getOptions() );
351 else if ( o == _line_up_renderable_data_cbmi ) {
352 if ( !_line_up_renderable_data_cbmi.isSelected() ) {
353 _right_line_up_domains_cbmi.setSelected( false );
355 updateOptions( getOptions() );
357 else if ( o == _right_line_up_domains_cbmi ) {
358 if ( _right_line_up_domains_cbmi.isSelected() ) {
359 _line_up_renderable_data_cbmi.setSelected( true );
361 updateOptions( getOptions() );
367 public void destroy() {
368 AptxUtil.printAppletMessage( NAME, "going to be destroyed " );
369 removeAllTextFrames();
370 if ( getMainPanel() != null ) {
371 getMainPanel().terminate();
376 * This method returns the current external node data which
377 * has been selected by the user by clicking the "Return ..."
378 * menu item. This method is expected to be called from Javascript or
381 * @return current external node data as String
383 public String getCurrentExternalNodesDataBuffer() {
384 return getCurrentTreePanel().getCurrentExternalNodesDataBufferAsString();
387 public int getCurrentExternalNodesDataBufferChangeCounter() {
388 return getCurrentTreePanel().getCurrentExternalNodesDataBufferChangeCounter();
391 public int getCurrentExternalNodesDataBufferLength() {
392 return getCurrentTreePanel().getCurrentExternalNodesDataBufferAsString().length();
396 * This method returns the current phylogeny as a string in the chosen format
398 * @param format must be NH, NHX, NEXUS or PHYLOXML
399 * @return the phylogeny string
400 * @author Herve Menager
402 public String getCurrentPhylogeny( final String format ) {
403 removeAllTextFrames();
404 if ( ( getMainPanel().getCurrentPhylogeny() == null ) || getMainPanel().getCurrentPhylogeny().isEmpty()
405 || ( getMainPanel().getCurrentPhylogeny().getNumberOfExternalNodes() > 10000 ) ) {
408 switch ( ForesterConstants.PhylogeneticTreeFormats.valueOf( format ) ) {
410 return getMainPanel().getCurrentPhylogeny().toNewHampshire();
412 return getMainPanel().getCurrentPhylogeny().toNewHampshireX();
414 return getMainPanel().getCurrentPhylogeny().toNexus();
416 return getMainPanel().getCurrentPhylogeny().toPhyloXML( -1 );
424 * This method returns a view of the current phylogeny in a chosen
425 * graphics format, base64-encoded in a string so that in can be used
428 * @param format must be GraphicsExportType (gif, jpg, pdf, png, tif, bmp)
429 * @return the phylogeny string
430 * @author Herve Menager
432 public String getCurrentPhylogenyGraphicsAsBase64EncodedString( final String format ) {
433 final ByteArrayOutputStream baos = new ByteArrayOutputStream();
435 AptxUtil.writePhylogenyToGraphicsByteArrayOutputStream( baos,
436 _mainpanel.getWidth(),
437 _mainpanel.getHeight(),
438 getCurrentTreePanel(),
439 getCurrentTreePanel().getControlPanel(),
440 GraphicsExportType.valueOf( format ),
443 catch ( final IOException ioe ) {
444 ForesterUtil.printErrorMessage( NAME, ioe.toString() );
445 ioe.printStackTrace();
446 JOptionPane.showMessageDialog( this,
447 NAME + ": Failed to generate graphics: " + "\nException: " + ioe,
448 "Failed to generate graphics",
449 JOptionPane.ERROR_MESSAGE );
452 final byte[] bytes = baos.toByteArray();
453 final String dataImg = Base64.encodeBase64String( bytes );
457 public Options getOptions() {
463 final String config_filename = getParameter( Constants.APPLET_PARAM_NAME_FOR_CONFIG_FILE_URL );
464 AptxUtil.printAppletMessage( NAME, "URL for configuration file is: " + config_filename );
465 final Configuration configuration = new Configuration( config_filename, true, true, true );
466 setConfiguration( configuration );
467 setOptions( Options.createInstance( configuration ) );
469 final String tree_url_str = getParameter( Constants.APPLET_PARAM_NAME_FOR_URL_OF_TREE_TO_LOAD );
470 if ( ForesterUtil.isEmpty( tree_url_str ) ) {
471 ForesterUtil.printErrorMessage( NAME, "could not get tree URL from "
472 + Constants.APPLET_PARAM_NAME_FOR_URL_OF_TREE_TO_LOAD );
473 JOptionPane.showMessageDialog( this, NAME + ": could not get tree URL from "
474 + Constants.APPLET_PARAM_NAME_FOR_URL_OF_TREE_TO_LOAD, "Failed get URL", JOptionPane.ERROR_MESSAGE );
477 AptxUtil.printAppletMessage( NAME, "URL for phylogenies is " + tree_url_str );
478 // Get URL to tree file
481 phys_url = new URL( tree_url_str );
483 catch ( final Exception e ) {
484 ForesterUtil.printErrorMessage( NAME, "error: " + e );
486 JOptionPane.showMessageDialog( this, NAME + ": Could not create URL from: \"" + tree_url_str
487 + "\"\nException: " + e, "Failed to create URL", JOptionPane.ERROR_MESSAGE );
489 if ( phys_url == null ) {
490 ForesterUtil.printErrorMessage( NAME, "failed to get tree URL from "
491 + Constants.APPLET_PARAM_NAME_FOR_URL_OF_TREE_TO_LOAD );
492 JOptionPane.showMessageDialog( this,
493 NAME + ": Could not create URL from: \"" + tree_url_str,
494 "Failed to create URL",
495 JOptionPane.ERROR_MESSAGE );
498 // Load the tree from URL
499 Phylogeny[] phys = null;
501 phys = AptxUtil.readPhylogeniesFromUrl( phys_url,
502 getConfiguration().isValidatePhyloXmlAgainstSchema(),
503 getConfiguration().isReplaceUnderscoresInNhParsing(),
504 getConfiguration().isInternalNumberAreConfidenceForNhParsing(),
505 getConfiguration().getTaxonomyExtraction(),
506 getConfiguration().isMidpointReroot() );
508 catch ( final Exception e ) {
509 ForesterUtil.printErrorMessage( NAME, e.toString() );
511 JOptionPane.showMessageDialog( this,
512 NAME + ": Failed to read phylogenies: " + "\nException: " + e,
513 "Failed to read phylogenies",
514 JOptionPane.ERROR_MESSAGE );
516 if ( phys == null ) {
517 ForesterUtil.printErrorMessage( NAME, "phylogenies from [" + phys_url + "] are null" );
518 JOptionPane.showMessageDialog( this,
519 NAME + ": phylogenies from [" + phys_url + "] are null",
520 "Failed to read phylogenies",
521 JOptionPane.ERROR_MESSAGE );
524 else if ( phys.length < 1 ) {
525 ForesterUtil.printErrorMessage( NAME, "phylogenies from [" + phys_url + "] are empty" );
526 JOptionPane.showMessageDialog( this,
527 NAME + ": phylogenies from [" + phys_url + "] are empty",
528 "Failed to read phylogenies",
529 JOptionPane.ERROR_MESSAGE );
533 AptxUtil.printAppletMessage( NAME, "loaded " + phys.length + " phylogenies from: " + phys_url );
536 final String species_tree_url_str = getParameter( Constants.APPLET_PARAM_NAME_FOR_URL_OF_SPECIES_TREE_TO_LOAD );
537 if ( !ForesterUtil.isEmpty( species_tree_url_str ) ) {
538 AptxUtil.printAppletMessage( NAME, "URL of species tree to load: \"" + species_tree_url_str + "\"" );
539 Phylogeny[] species_trees = null;
541 final URL species_tree_url = new URL( species_tree_url_str );
542 species_trees = AptxUtil.readPhylogeniesFromUrl( species_tree_url,
543 configuration.isValidatePhyloXmlAgainstSchema(),
544 configuration.isReplaceUnderscoresInNhParsing(),
546 TAXONOMY_EXTRACTION.NO,
549 catch ( final IOException e ) {
550 ForesterUtil.printErrorMessage( NAME, "could not read species tree from [" + species_tree_url_str
552 JOptionPane.showMessageDialog( this, NAME + ": could not read species tree from ["
553 + species_tree_url_str + "]", "Failed to read species tree", JOptionPane.ERROR_MESSAGE );
555 if ( ( species_trees != null ) && ( species_trees.length > 0 ) ) {
556 AptxUtil.printAppletMessage( NAME, "successfully read species tree" );
557 if ( species_trees[ 0 ].isEmpty() ) {
558 ForesterUtil.printErrorMessage( NAME, "species tree is empty" );
560 else if ( !species_trees[ 0 ].isRooted() ) {
561 ForesterUtil.printErrorMessage( NAME, "species tree is not rooted" );
564 setSpeciesTree( species_trees[ 0 ] );
565 AptxUtil.printAppletMessage( NAME, "species tree OK" );
572 setMainPanel( new MainPanelApplets( getConfiguration(), this ) );
573 _jmenubar = new JMenuBar();
574 if ( !getConfiguration().isHideControlPanelAndMenubar() ) {
575 if ( !getConfiguration().isUseNativeUI() ) {
576 _jmenubar.setBackground( getConfiguration().getGuiMenuBackgroundColor() );
578 if ( getSpeciesTree() != null ) {
587 setJMenuBar( _jmenubar );
589 final Container contentpane = getContentPane();
590 contentpane.setLayout( new BorderLayout() );
591 contentpane.add( getMainPanel(), BorderLayout.CENTER );
592 addComponentListener( new ComponentAdapter() {
595 public void componentResized( final ComponentEvent e ) {
596 if ( getMainPanel().getCurrentTreePanel() != null ) {
597 getMainPanel().getCurrentTreePanel()
598 .calcParametersForPainting( getMainPanel().getCurrentTreePanel().getWidth(),
599 getMainPanel().getCurrentTreePanel().getHeight(),
600 getOptions().isAllowFontSizeChange() );
604 if ( getConfiguration().isUseTabbedDisplay() ) {
606 AptxUtil.printAppletMessage( NAME, "using tabbed display" );
607 AptxUtil.addPhylogeniesToTabs( phys,
608 new File( phys_url.getFile() ).getName(),
613 catch ( final Exception e ) {
614 ForesterUtil.printErrorMessage( NAME, e.toString() );
619 AptxUtil.printAppletMessage( NAME, "not using tabbed display" );
620 if ( getSpeciesTree() != null ) {
621 AptxUtil.printAppletMessage( NAME,
622 "Warning: gsdi (gene duplication inference) only available tabbed display" );
624 AptxUtil.addPhylogenyToPanel( phys, getConfiguration(), getMainPanel() );
628 getMainPanel().getControlPanel().showWholeAll();
629 getMainPanel().getControlPanel().showWhole();
631 getCurrentTreePanel().getControlPanel().getSequenceRelationTypeBox().removeAllItems();
632 for( final SequenceRelation.SEQUENCE_RELATION_TYPE type : getMainPanel().getCurrentPhylogeny()
633 .getRelevantSequenceRelationTypes() ) {
634 getCurrentTreePanel().getControlPanel().getSequenceRelationTypeBox().addItem( type );
636 final String default_relation = getParameter( Constants.APPLET_PARAM_NAME_FOR_DEFAULT_SEQUENCE_RELATION_TYPE );
637 if ( default_relation != null ) {
638 getCurrentTreePanel().getControlPanel().getSequenceRelationTypeBox().setSelectedItem( default_relation );
640 final String default_sequence = getParameter( Constants.APPLET_PARAM_NAME_FOR_DEFAULT_QUERY_SEQUENCE );
641 if ( default_sequence != null ) {
642 getCurrentTreePanel().getControlPanel().getSequenceRelationBox().setSelectedItem( default_sequence );
646 AptxUtil.printAppletMessage( NAME, "successfully initialized" );
649 catch ( final Exception e ) {
650 ForesterUtil.printErrorMessage( NAME, e.toString() );
655 public void showTextFrame( final String s, final String title ) {
657 _textframes.addLast( TextFrame.instantiate( s, title, _textframes ) );
661 public void start() {
662 if ( getMainPanel() != null ) {
663 getMainPanel().validate();
666 requestFocusInWindow();
668 AptxUtil.printAppletMessage( NAME, "started" );
671 void buildAnalysisMenu() {
672 _analysis_menu = MainFrame.createMenu( "Analysis", getConfiguration() );
673 _analysis_menu.add( _gsdi_item = new JMenuItem( "GSDI (Generalized Speciation Duplication Inference)" ) );
674 _analysis_menu.add( _gsdir_item = new JMenuItem( "GSDIR (GSDI with re-rooting)" ) );
675 customizeJMenuItem( _gsdi_item );
676 customizeJMenuItem( _gsdir_item );
677 // _analysis_menu.addSeparator();
678 // _analysis_menu.add( _lineage_inference = new JMenuItem( INFER_ANCESTOR_TAXONOMIES ) );
679 // customizeJMenuItem( _lineage_inference );
680 // _lineage_inference.setToolTipText( "Inference of ancestor taxonomies/lineages" );
681 _jmenubar.add( _analysis_menu );
684 void buildFontSizeMenu() {
685 _font_size_menu = MainFrame.createMenu( MainFrame.FONT_SIZE_MENU_LABEL, getConfiguration() );
686 _font_size_menu.add( _super_tiny_fonts_mi = new JMenuItem( "Super tiny fonts" ) );
687 _font_size_menu.add( _tiny_fonts_mi = new JMenuItem( "Tiny fonts" ) );
688 _font_size_menu.add( _small_fonts_mi = new JMenuItem( "Small fonts" ) );
689 _font_size_menu.add( _medium_fonts_mi = new JMenuItem( "Medium fonts" ) );
690 _font_size_menu.add( _large_fonts_mi = new JMenuItem( "Large fonts" ) );
691 customizeJMenuItem( _super_tiny_fonts_mi );
692 customizeJMenuItem( _tiny_fonts_mi );
693 customizeJMenuItem( _small_fonts_mi );
694 customizeJMenuItem( _medium_fonts_mi );
695 customizeJMenuItem( _large_fonts_mi );
696 _jmenubar.add( _font_size_menu );
699 void buildHelpMenu() {
700 _help_jmenu = MainFrame.createMenu( "Help", getConfiguration() );
701 _help_jmenu.add( _help_item = new JMenuItem( "Documentation" ) );
702 _help_jmenu.addSeparator();
703 _help_jmenu.add( _website_item = new JMenuItem( "Archaeopteryx Home" ) );
704 _aptx_ref_item = new JMenuItem( "Archaeopteryx Reference" );
705 _help_jmenu.add( _phyloxml_website_item = new JMenuItem( "phyloXML Home" ) );
706 _help_jmenu.add( _phyloxml_ref_item = new JMenuItem( "phyloXML Reference" ) );
707 _help_jmenu.addSeparator();
708 _help_jmenu.add( _about_item = new JMenuItem( "About" ) );
709 customizeJMenuItem( _help_item );
710 customizeJMenuItem( _website_item );
711 customizeJMenuItem( _phyloxml_website_item );
712 customizeJMenuItem( _aptx_ref_item );
713 customizeJMenuItem( _phyloxml_ref_item );
714 customizeJMenuItem( _about_item );
715 _phyloxml_ref_item.setToolTipText( MainFrame.PHYLOXML_REF_TOOL_TIP );
716 _aptx_ref_item.setToolTipText( MainFrame.APTX_REF_TOOL_TIP );
717 _jmenubar.add( _help_jmenu );
720 void buildOptionsMenu() {
721 _options_jmenu = MainFrame.createMenu( MainFrame.OPTIONS_HEADER, getConfiguration() );
722 _options_jmenu.addChangeListener( new ChangeListener() {
725 public void stateChanged( final ChangeEvent e ) {
726 MainFrame.setOvPlacementColorChooseMenuItem( _overview_placment_mi, getOptions() );
727 MainFrame.setTextColorChooseMenuItem( _switch_colors_mi, getCurrentTreePanel() );
729 .setTextMinSupportMenuItem( _choose_minimal_confidence_mi, getOptions(), getCurrentTreePanel() );
730 MainFrame.setTextForFontChooserMenuItem( _choose_font_mi, MainFrame
731 .createCurrentFontDesc( getMainPanel().getTreeFontSet() ) );
732 MainFrame.setCycleNodeFillMenuItem( _cycle_node_fill_mi, getOptions() );
733 MainFrame.setCycleNodeShapeMenuItem( _cycle_node_shape_mi, getOptions() );
734 MainFrame.setTextNodeSizeMenuItem( _choose_node_size_mi, getOptions() );
736 getMainPanel().getControlPanel().setVisibilityOfDomainStrucureCB();
737 getMainPanel().getControlPanel().setVisibilityOfX();
739 catch ( final Exception ignore ) {
740 // do nothing, not important.
744 _options_jmenu.add( MainFrame.customizeMenuItemAsLabel( new JMenuItem( MainFrame.DISPLAY_SUBHEADER ),
745 getConfiguration() ) );
747 .add( _ext_node_dependent_cladogram_rbmi = new JRadioButtonMenuItem( MainFrame.NONUNIFORM_CLADOGRAMS_LABEL ) );
748 _options_jmenu.add( _uniform_cladograms_rbmi = new JRadioButtonMenuItem( MainFrame.UNIFORM_CLADOGRAMS_LABEL ) );
750 .add( _non_lined_up_cladograms_rbmi = new JRadioButtonMenuItem( MainFrame.NON_LINED_UP_CLADOGRAMS_LABEL ) );
751 _radio_group_1 = new ButtonGroup();
752 _radio_group_1.add( _ext_node_dependent_cladogram_rbmi );
753 _radio_group_1.add( _uniform_cladograms_rbmi );
754 _radio_group_1.add( _non_lined_up_cladograms_rbmi );
755 _options_jmenu.add( _show_overview_cbmi = new JCheckBoxMenuItem( MainFrame.SHOW_OVERVIEW_LABEL ) );
756 _options_jmenu.add( _show_scale_cbmi = new JCheckBoxMenuItem( MainFrame.DISPLAY_SCALE_LABEL ) );
758 .add( _show_default_node_shapes_internal_cbmi = new JCheckBoxMenuItem( MainFrame.DISPLAY_NODE_BOXES_LABEL_INT ) );
760 .add( _show_default_node_shapes_external_cbmi = new JCheckBoxMenuItem( MainFrame.DISPLAY_NODE_BOXES_LABEL_EXT ) );
762 .add( _show_default_node_shapes_for_marked_cbmi = new JCheckBoxMenuItem( MainFrame.DISPLAY_NODE_BOXES_LABEL_EXT ) );
763 _options_jmenu.add( _line_up_renderable_data_cbmi = new JCheckBoxMenuItem( MainFrame.LINE_UP_RENDERABLE_DATA ) );
764 if ( getConfiguration().doDisplayOption( Configuration.show_domain_architectures ) ) {
765 _options_jmenu.add( _right_line_up_domains_cbmi = new JCheckBoxMenuItem( MainFrame.RIGHT_LINE_UP_DOMAINS ) );
766 _options_jmenu.add( _show_domain_labels = new JCheckBoxMenuItem( MainFrame.SHOW_DOMAIN_LABELS_LABEL ) );
768 _options_jmenu.add( _show_annotation_ref_source = new JCheckBoxMenuItem( MainFrame.SHOW_ANN_REF_SOURCE_LABEL ) );
769 _options_jmenu.add( _show_confidence_stddev_cbmi = new JCheckBoxMenuItem( MainFrame.SHOW_CONF_STDDEV_LABEL ) );
771 .add( _color_by_taxonomic_group_cbmi = new JCheckBoxMenuItem( MainFrame.COLOR_BY_TAXONOMIC_GROUP ) );
773 .add( _color_labels_same_as_parent_branch = new JCheckBoxMenuItem( MainFrame.COLOR_LABELS_LABEL ) );
774 _color_labels_same_as_parent_branch.setToolTipText( MainFrame.COLOR_LABELS_TIP );
775 _options_jmenu.add( _abbreviate_scientific_names = new JCheckBoxMenuItem( MainFrame.ABBREV_SN_LABEL ) );
776 _options_jmenu.add( _label_direction_cbmi = new JCheckBoxMenuItem( MainFrame.LABEL_DIRECTION_LABEL ) );
777 _label_direction_cbmi.setToolTipText( MainFrame.LABEL_DIRECTION_TIP );
778 _options_jmenu.add( _screen_antialias_cbmi = new JCheckBoxMenuItem( MainFrame.SCREEN_ANTIALIAS_LABEL ) );
779 _options_jmenu.add( _background_gradient_cbmi = new JCheckBoxMenuItem( MainFrame.BG_GRAD_LABEL ) );
780 _options_jmenu.add( _cycle_node_shape_mi = new JMenuItem( MainFrame.CYCLE_NODE_SHAPE_LABEL ) );
781 _options_jmenu.add( _cycle_node_fill_mi = new JMenuItem( MainFrame.CYCLE_NODE_FILL_LABEL ) );
782 _options_jmenu.add( _choose_node_size_mi = new JMenuItem( MainFrame.CHOOSE_NODE_SIZE_LABEL ) );
783 _options_jmenu.add( _choose_minimal_confidence_mi = new JMenuItem( "" ) );
784 _options_jmenu.add( _overview_placment_mi = new JMenuItem( "" ) );
785 _options_jmenu.add( _switch_colors_mi = new JMenuItem( "" ) );
786 _options_jmenu.add( _choose_font_mi = new JMenuItem( "" ) );
787 _options_jmenu.addSeparator();
788 _options_jmenu.add( MainFrame.customizeMenuItemAsLabel( new JMenuItem( MainFrame.SEARCH_SUBHEADER ),
789 getConfiguration() ) );
791 .add( _search_case_senstive_cbmi = new JCheckBoxMenuItem( MainFrame.SEARCH_CASE_SENSITIVE_LABEL ) );
792 _options_jmenu.add( _search_whole_words_only_cbmi = new JCheckBoxMenuItem( MainFrame.SEARCH_TERMS_ONLY_LABEL ) );
794 .add( _inverse_search_result_cbmi = new JCheckBoxMenuItem( MainFrame.INVERSE_SEARCH_RESULT_LABEL ) );
795 customizeJMenuItem( _choose_font_mi );
796 customizeJMenuItem( _choose_minimal_confidence_mi );
797 customizeJMenuItem( _switch_colors_mi );
798 customizeJMenuItem( _overview_placment_mi );
799 customizeCheckBoxMenuItem( _color_by_taxonomic_group_cbmi, getOptions().isColorByTaxonomicGroup() );
800 customizeCheckBoxMenuItem( _label_direction_cbmi,
801 getOptions().getNodeLabelDirection() == NODE_LABEL_DIRECTION.RADIAL );
802 customizeCheckBoxMenuItem( _screen_antialias_cbmi, getOptions().isAntialiasScreen() );
803 customizeCheckBoxMenuItem( _background_gradient_cbmi, getOptions().isBackgroundColorGradient() );
804 customizeCheckBoxMenuItem( _show_domain_labels, getOptions().isShowDomainLabels() );
805 customizeCheckBoxMenuItem( _show_annotation_ref_source, getOptions().isShowAnnotationRefSource() );
806 customizeCheckBoxMenuItem( _abbreviate_scientific_names, getOptions().isAbbreviateScientificTaxonNames() );
807 customizeCheckBoxMenuItem( _show_default_node_shapes_external_cbmi, getOptions()
808 .isShowDefaultNodeShapesExternal() );
809 customizeCheckBoxMenuItem( _show_default_node_shapes_internal_cbmi, getOptions()
810 .isShowDefaultNodeShapesInternal() );
811 customizeCheckBoxMenuItem( _show_default_node_shapes_for_marked_cbmi, getOptions()
812 .isShowDefaultNodeShapesForMarkedNodes() );
813 customizeJMenuItem( _cycle_node_shape_mi );
814 customizeJMenuItem( _cycle_node_fill_mi );
815 customizeJMenuItem( _choose_node_size_mi );
816 customizeCheckBoxMenuItem( _color_labels_same_as_parent_branch, getOptions().isColorLabelsSameAsParentBranch() );
817 customizeCheckBoxMenuItem( _search_case_senstive_cbmi, getOptions().isSearchCaseSensitive() );
818 customizeCheckBoxMenuItem( _show_scale_cbmi, getOptions().isShowScale() );
819 customizeRadioButtonMenuItem( _non_lined_up_cladograms_rbmi,
820 getOptions().getCladogramType() == CLADOGRAM_TYPE.NON_LINED_UP );
821 customizeRadioButtonMenuItem( _uniform_cladograms_rbmi,
822 getOptions().getCladogramType() == CLADOGRAM_TYPE.TOTAL_NODE_SUM_DEP );
823 customizeRadioButtonMenuItem( _ext_node_dependent_cladogram_rbmi,
824 getOptions().getCladogramType() == CLADOGRAM_TYPE.EXT_NODE_SUM_DEP );
825 customizeCheckBoxMenuItem( _show_overview_cbmi, getOptions().isShowOverview() );
826 customizeCheckBoxMenuItem( _search_whole_words_only_cbmi, getOptions().isMatchWholeTermsOnly() );
827 customizeCheckBoxMenuItem( _inverse_search_result_cbmi, getOptions().isInverseSearchResult() );
828 customizeCheckBoxMenuItem( _show_confidence_stddev_cbmi, getOptions().isShowConfidenceStddev() );
829 customizeCheckBoxMenuItem( _line_up_renderable_data_cbmi, getOptions().isLineUpRendarableNodeData() );
830 customizeCheckBoxMenuItem( _right_line_up_domains_cbmi, getOptions().isRightLineUpDomains() );
831 _jmenubar.add( _options_jmenu );
834 void buildToolsMenu() {
835 _tools_menu = MainFrame.createMenu( "Tools", getConfiguration() );
836 _tools_menu.add( _confcolor_item = new JMenuItem( "Colorize Branches Depending on Confidence" ) );
837 customizeJMenuItem( _confcolor_item );
838 _tools_menu.add( _taxcolor_item = new JMenuItem( "Taxonomy Colorize Branches" ) );
839 customizeJMenuItem( _taxcolor_item );
840 _tools_menu.addSeparator();
841 _tools_menu.add( _remove_visual_styles_item = new JMenuItem( "Delete All Visual Styles From Nodes" ) );
842 _remove_visual_styles_item
843 .setToolTipText( "To remove all node visual styles (fonts, colors) from the current phylogeny." );
844 customizeJMenuItem( _remove_visual_styles_item );
845 _tools_menu.add( _remove_branch_color_item = new JMenuItem( "Delete All Colors From Branches" ) );
846 _remove_branch_color_item.setToolTipText( "To remove all branch color values from the current phylogeny." );
847 customizeJMenuItem( _remove_branch_color_item );
848 _tools_menu.addSeparator();
849 _tools_menu.add( _midpoint_root_item = new JMenuItem( "Midpoint-Root" ) );
850 customizeJMenuItem( _midpoint_root_item );
851 _tools_menu.addSeparator();
852 _tools_menu.add( _collapse_species_specific_subtrees = new JMenuItem( "Collapse Species-Specific Subtrees" ) );
853 customizeJMenuItem( _collapse_species_specific_subtrees );
854 _jmenubar.add( _tools_menu );
857 void buildTypeMenu() {
858 _type_menu = MainFrame.createMenu( MainFrame.TYPE_MENU_HEADER, getConfiguration() );
859 _type_menu.add( _rectangular_type_cbmi = new JCheckBoxMenuItem( MainFrame.RECTANGULAR_TYPE_CBMI_LABEL ) );
860 _type_menu.add( _euro_type_cbmi = new JCheckBoxMenuItem( MainFrame.EURO_TYPE_CBMI_LABEL ) );
861 _type_menu.add( _rounded_type_cbmi = new JCheckBoxMenuItem( MainFrame.ROUNDED_TYPE_CBMI_LABEL ) );
862 _type_menu.add( _curved_type_cbmi = new JCheckBoxMenuItem( MainFrame.CURVED_TYPE_CBMI_LABEL ) );
863 _type_menu.add( _triangular_type_cbmi = new JCheckBoxMenuItem( MainFrame.TRIANGULAR_TYPE_CBMI_LABEL ) );
864 _type_menu.add( _convex_type_cbmi = new JCheckBoxMenuItem( MainFrame.CONVEX_TYPE_CBMI_LABEL ) );
865 _type_menu.add( _unrooted_type_cbmi = new JCheckBoxMenuItem( MainFrame.UNROOTED_TYPE_CBMI_LABEL ) );
866 _type_menu.add( _circular_type_cbmi = new JCheckBoxMenuItem( MainFrame.CIRCULAR_TYPE_CBMI_LABEL ) );
867 customizeCheckBoxMenuItem( _rectangular_type_cbmi, false );
868 customizeCheckBoxMenuItem( _triangular_type_cbmi, false );
869 customizeCheckBoxMenuItem( _euro_type_cbmi, false );
870 customizeCheckBoxMenuItem( _rounded_type_cbmi, false );
871 customizeCheckBoxMenuItem( _curved_type_cbmi, false );
872 customizeCheckBoxMenuItem( _convex_type_cbmi, false );
873 customizeCheckBoxMenuItem( _unrooted_type_cbmi, false );
874 customizeCheckBoxMenuItem( _circular_type_cbmi, false );
875 _unrooted_type_cbmi.setToolTipText( MainFrame.USE_MOUSEWHEEL_SHIFT_TO_ROTATE );
876 _circular_type_cbmi.setToolTipText( MainFrame.USE_MOUSEWHEEL_SHIFT_TO_ROTATE );
877 initializeTypeMenu( getOptions() );
878 _jmenubar.add( _type_menu );
881 void buildViewMenu() {
882 _view_jmenu = MainFrame.createMenu( "View", getConfiguration() );
884 .add( _display_basic_information_item = new JMenuItem( MainFrame.SHOW_BASIC_TREE_INFORMATION_LABEL ) );
885 _view_jmenu.addSeparator();
886 _view_jmenu.add( _view_as_XML_item = new JMenuItem( "as phyloXML" ) );
887 _view_jmenu.add( _view_as_NH_item = new JMenuItem( "as Newick" ) );
888 _view_jmenu.add( _view_as_nexus_item = new JMenuItem( "as Nexus" ) );
889 customizeJMenuItem( _display_basic_information_item );
890 customizeJMenuItem( _view_as_NH_item );
891 customizeJMenuItem( _view_as_XML_item );
892 customizeJMenuItem( _view_as_nexus_item );
893 _jmenubar.add( _view_jmenu );
896 void checkTextFrames() {
897 if ( _textframes.size() > 5 ) {
899 if ( _textframes.getFirst() != null ) {
900 _textframes.getFirst().removeMe();
903 _textframes.removeFirst();
906 catch ( final NoSuchElementException e ) {
912 void clearCurrentExternalNodesDataBuffer() {
913 getCurrentTreePanel().clearCurrentExternalNodesDataBuffer();
916 void customizeCheckBoxMenuItem( final JCheckBoxMenuItem item, final boolean is_selected ) {
917 if ( item != null ) {
918 item.setFont( MainFrame.menu_font );
919 if ( !getConfiguration().isUseNativeUI() ) {
920 item.setBackground( getConfiguration().getGuiMenuBackgroundColor() );
921 item.setForeground( getConfiguration().getGuiMenuTextColor() );
923 item.setSelected( is_selected );
924 item.addActionListener( this );
928 void customizeJMenuItem( final JMenuItem jmi ) {
929 jmi.setFont( MainFrame.menu_font );
930 if ( !getConfiguration().isUseNativeUI() ) {
931 jmi.setBackground( getConfiguration().getGuiMenuBackgroundColor() );
932 jmi.setForeground( getConfiguration().getGuiMenuTextColor() );
934 jmi.addActionListener( this );
937 void displayBasicInformation() {
938 if ( ( getMainPanel() != null ) && ( getMainPanel().getCurrentPhylogeny() != null )
939 && !getMainPanel().getCurrentPhylogeny().isEmpty() ) {
940 String title = "Basic Information";
941 if ( !ForesterUtil.isEmpty( getMainPanel().getCurrentPhylogeny().getName() ) ) {
942 title = title + " for \"" + _mainpanel.getCurrentPhylogeny().getName() + "\"";
944 showTextFrame( AptxUtil.createBasicInformation( getMainPanel().getCurrentPhylogeny(), null ), title );
949 if ( !isOKforSDI( false, true ) ) {
952 if ( !_mainpanel.getCurrentPhylogeny().isRooted() ) {
953 JOptionPane.showMessageDialog( this,
954 "Gene tree is not rooted.",
955 "Cannot execute GSDI",
956 JOptionPane.ERROR_MESSAGE );
959 final Phylogeny gene_tree = _mainpanel.getCurrentPhylogeny().copy();
960 gene_tree.setAllNodesToNotCollapse();
961 gene_tree.recalculateNumberOfExternalDescendants( false );
963 final Phylogeny species_tree = _species_tree.copy();
965 gsdi = new GSDI( gene_tree, species_tree, false, true, true, true );
967 catch ( final SDIException e ) {
968 JOptionPane.showMessageDialog( this,
969 e.getLocalizedMessage(),
971 JOptionPane.ERROR_MESSAGE );
974 catch ( final Exception e ) {
975 AptxUtil.unexpectedException( e );
978 gene_tree.setRerootable( false );
979 gene_tree.clearHashIdToNodeMap();
980 gene_tree.recalculateNumberOfExternalDescendants( true );
981 _mainpanel.addPhylogenyInNewTab( gene_tree, getConfiguration(), "gene tree", null );
982 getMainPanel().getControlPanel().setShowEvents( true );
984 final int selected = _mainpanel.getTabbedPane().getSelectedIndex();
985 _mainpanel.addPhylogenyInNewTab( species_tree, getConfiguration(), "species tree", null );
987 _mainpanel.getTabbedPane().setSelectedIndex( selected );
989 _mainpanel.getCurrentTreePanel().setEdited( true );
990 final int poly = PhylogenyMethods.countNumberOfPolytomies( species_tree );
991 if ( gsdi.getStrippedExternalGeneTreeNodes().size() > 0 ) {
992 JOptionPane.showMessageDialog( this,
993 "Duplications: " + gsdi.getDuplicationsSum() + "\n"
994 + "Potential duplications: "
995 + gsdi.getSpeciationOrDuplicationEventsSum() + "\n"
996 + "Speciations: " + gsdi.getSpeciationsSum() + "\n"
997 + "Stripped gene tree nodes: "
998 + gsdi.getStrippedExternalGeneTreeNodes().size() + "\n"
999 + "Taxonomy linkage based on: " + gsdi.getTaxCompBase() + "\n"
1000 + "Number of polytomies in species tree used: " + poly + "\n",
1001 "GSDI successfully completed",
1002 JOptionPane.WARNING_MESSAGE );
1005 JOptionPane.showMessageDialog( this,
1006 "Duplications: " + gsdi.getDuplicationsSum() + "\n"
1007 + "Potential duplications: "
1008 + gsdi.getSpeciationOrDuplicationEventsSum() + "\n"
1009 + "Speciations: " + gsdi.getSpeciationsSum() + "\n"
1010 + "Stripped gene tree nodes: "
1011 + gsdi.getStrippedExternalGeneTreeNodes().size() + "\n"
1012 + "Taxonomy linkage based on: " + gsdi.getTaxCompBase() + "\n"
1013 + "Number of polytomies in species tree used: " + poly + "\n",
1014 "GSDI successfully completed",
1015 JOptionPane.INFORMATION_MESSAGE );
1019 void executeGSDIR() {
1020 if ( !isOKforSDI( false, false ) ) {
1023 final int p = PhylogenyMethods.countNumberOfPolytomies( _mainpanel.getCurrentPhylogeny() );
1025 && !( ( p == 1 ) && ( _mainpanel.getCurrentPhylogeny().getRoot().getNumberOfDescendants() == 3 ) ) ) {
1026 JOptionPane.showMessageDialog( this,
1027 "Gene tree is not completely binary",
1028 "Cannot execute GSDI",
1029 JOptionPane.ERROR_MESSAGE );
1032 final Phylogeny gene_tree = _mainpanel.getCurrentPhylogeny().copy();
1033 gene_tree.setAllNodesToNotCollapse();
1034 gene_tree.recalculateNumberOfExternalDescendants( false );
1036 final Phylogeny species_tree = _species_tree.copy();
1038 gsdir = new GSDIR( gene_tree, species_tree, true, true, true );
1040 catch ( final SDIException e ) {
1041 JOptionPane.showMessageDialog( this,
1042 e.getLocalizedMessage(),
1043 "Error during GSDIR",
1044 JOptionPane.ERROR_MESSAGE );
1047 catch ( final Exception e ) {
1048 AptxUtil.unexpectedException( e );
1051 final Phylogeny result_gene_tree = gsdir.getMinDuplicationsSumGeneTree();
1052 result_gene_tree.setRerootable( false );
1053 result_gene_tree.clearHashIdToNodeMap();
1054 result_gene_tree.recalculateNumberOfExternalDescendants( true );
1055 PhylogenyMethods.orderAppearance( result_gene_tree.getRoot(), true, true, DESCENDANT_SORT_PRIORITY.NODE_NAME );
1056 _mainpanel.addPhylogenyInNewTab( result_gene_tree, getConfiguration(), "gene tree", null );
1057 getMainPanel().getControlPanel().setShowEvents( true );
1059 final int selected = _mainpanel.getTabbedPane().getSelectedIndex();
1060 _mainpanel.addPhylogenyInNewTab( species_tree, getConfiguration(), "species tree", null );
1062 _mainpanel.getTabbedPane().setSelectedIndex( selected );
1064 _mainpanel.getCurrentTreePanel().setEdited( true );
1065 final int poly = PhylogenyMethods.countNumberOfPolytomies( species_tree );
1066 if ( gsdir.getStrippedExternalGeneTreeNodes().size() > 0 ) {
1067 JOptionPane.showMessageDialog( this,
1068 "Minimal duplications: " + gsdir.getMinDuplicationsSum() + "\n"
1069 + "Speciations: " + gsdir.getSpeciationsSum() + "\n"
1070 + "Stripped gene tree nodes: "
1071 + gsdir.getStrippedExternalGeneTreeNodes().size() + "\n"
1072 + "Taxonomy linkage based on: " + gsdir.getTaxCompBase() + "\n"
1073 + "Number of polytomies in species tree used: " + poly + "\n",
1074 "GSDIR successfully completed",
1075 JOptionPane.WARNING_MESSAGE );
1078 JOptionPane.showMessageDialog( this,
1079 "Minimal duplications: " + gsdir.getMinDuplicationsSum() + "\n"
1080 + "Speciations: " + gsdir.getSpeciationsSum() + "\n"
1081 + "Stripped gene tree nodes: "
1082 + gsdir.getStrippedExternalGeneTreeNodes().size() + "\n"
1083 + "Taxonomy linkage based on: " + gsdir.getTaxCompBase() + "\n"
1084 + "Number of polytomies in species tree used: " + poly + "\n",
1085 "GSDIR successfully completed",
1086 JOptionPane.INFORMATION_MESSAGE );
1090 Configuration getConfiguration() {
1091 return _configuration;
1094 TreePanel getCurrentTreePanel() {
1095 return getMainPanel().getCurrentTreePanel();
1098 JCheckBoxMenuItem getlabelDirectionCbmi() {
1099 return _label_direction_cbmi;
1102 Options getOtions() {
1106 void initializeTypeMenu( final Options options ) {
1107 setTypeMenuToAllUnselected();
1109 switch ( options.getPhylogenyGraphicsType() ) {
1111 _convex_type_cbmi.setSelected( true );
1114 _curved_type_cbmi.setSelected( true );
1117 _euro_type_cbmi.setSelected( true );
1120 _rounded_type_cbmi.setSelected( true );
1123 _triangular_type_cbmi.setSelected( true );
1126 _unrooted_type_cbmi.setSelected( true );
1129 _circular_type_cbmi.setSelected( true );
1132 _rectangular_type_cbmi.setSelected( true );
1136 catch ( final NullPointerException np ) {
1137 // In all likelihood, this is caused by menu-less display.
1141 boolean isOKforSDI( final boolean species_tree_has_to_binary, final boolean gene_tree_has_to_binary ) {
1142 if ( ( _mainpanel.getCurrentPhylogeny() == null ) || _mainpanel.getCurrentPhylogeny().isEmpty() ) {
1145 else if ( ( _species_tree == null ) || _species_tree.isEmpty() ) {
1146 JOptionPane.showMessageDialog( this,
1147 "No species tree loaded",
1148 "Cannot execute GSDI",
1149 JOptionPane.ERROR_MESSAGE );
1152 else if ( species_tree_has_to_binary && !_species_tree.isCompletelyBinary() ) {
1153 JOptionPane.showMessageDialog( this,
1154 "Species tree is not completely binary",
1155 "Cannot execute GSDI",
1156 JOptionPane.ERROR_MESSAGE );
1159 else if ( gene_tree_has_to_binary && !_mainpanel.getCurrentPhylogeny().isCompletelyBinary() ) {
1160 JOptionPane.showMessageDialog( this,
1161 "Gene tree is not completely binary",
1162 "Cannot execute GSDI",
1163 JOptionPane.ERROR_MESSAGE );
1171 boolean isSubtreeDisplayed() {
1172 if ( getCurrentTreePanel() != null ) {
1173 if ( getCurrentTreePanel().isCurrentTreeIsSubtree() ) {
1175 .showMessageDialog( this,
1176 "This operation can only be performed on a complete tree, not on the currently displayed sub-tree only.",
1177 "Operation can not be exectuted on a sub-tree",
1178 JOptionPane.WARNING_MESSAGE );
1185 void removeAllTextFrames() {
1186 for( final TextFrame tf : _textframes ) {
1191 _textframes.clear();
1194 void setConfiguration( final Configuration configuration ) {
1195 _configuration = configuration;
1198 void setOptions( final Options options ) {
1202 void setSelectedTypeInTypeMenu( final PHYLOGENY_GRAPHICS_TYPE type ) {
1203 setTypeMenuToAllUnselected();
1207 _circular_type_cbmi.setSelected( true );
1210 _convex_type_cbmi.setSelected( true );
1213 _curved_type_cbmi.setSelected( true );
1216 _euro_type_cbmi.setSelected( true );
1219 _rounded_type_cbmi.setSelected( true );
1222 _rectangular_type_cbmi.setSelected( true );
1225 _triangular_type_cbmi.setSelected( true );
1228 _unrooted_type_cbmi.setSelected( true );
1231 throw new IllegalArgumentException( "unknown type: " + type );
1234 catch ( final NullPointerException np ) {
1235 // In all likelihood, this is caused by menu-less display.
1239 void setTypeMenuToAllUnselected() {
1240 if ( _convex_type_cbmi != null ) {
1241 _convex_type_cbmi.setSelected( false );
1243 if ( _curved_type_cbmi != null ) {
1244 _curved_type_cbmi.setSelected( false );
1246 if ( _euro_type_cbmi != null ) {
1247 _euro_type_cbmi.setSelected( false );
1249 if ( _rounded_type_cbmi != null ) {
1250 _rounded_type_cbmi.setSelected( false );
1252 if ( _triangular_type_cbmi != null ) {
1253 _triangular_type_cbmi.setSelected( false );
1255 if ( _rectangular_type_cbmi != null ) {
1256 _rectangular_type_cbmi.setSelected( false );
1258 if ( _unrooted_type_cbmi != null ) {
1259 _unrooted_type_cbmi.setSelected( false );
1261 if ( _circular_type_cbmi != null ) {
1262 _circular_type_cbmi.setSelected( false );
1267 _mainpanel.getControlPanel().showWhole();
1270 void switchColors() {
1271 final TreeColorSet colorset = getMainPanel().getCurrentTreePanel().getTreeColorSet();
1272 final ColorSchemeChooser csc = new ColorSchemeChooser( getMainPanel(), colorset );
1273 csc.setVisible( true );
1274 getMainPanel().setTreeColorSet( colorset );
1277 void typeChanged( final Object o ) {
1278 updateTypeCheckboxes( getOptions(), o );
1279 updateOptions( getOptions() );
1280 if ( getCurrentTreePanel() != null ) {
1281 final PHYLOGENY_GRAPHICS_TYPE previous_type = getCurrentTreePanel().getPhylogenyGraphicsType();
1282 final PHYLOGENY_GRAPHICS_TYPE new_type = getOptions().getPhylogenyGraphicsType();
1283 if ( ( ( previous_type == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) && ( new_type != PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) )
1284 || ( ( previous_type == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) && ( new_type != PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) )
1285 || ( ( previous_type != PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) && ( new_type == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) )
1286 || ( ( previous_type != PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) && ( new_type == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) ) ) {
1287 getCurrentTreePanel().getControlPanel().showWhole();
1289 if ( getCurrentTreePanel().isPhyHasBranchLengths() && ( new_type != PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) ) {
1290 getCurrentTreePanel().getControlPanel().setDrawPhylogramEnabled( true );
1293 getCurrentTreePanel().getControlPanel().setDrawPhylogramEnabled( false );
1295 getCurrentTreePanel().setPhylogenyGraphicsType( getOptions().getPhylogenyGraphicsType() );
1296 MainFrame.updateScreenTextAntialias( getMainPanel().getTreePanels() );
1300 void updateOptions( final Options options ) {
1301 options.setAntialiasScreen( ( _screen_antialias_cbmi != null ) && _screen_antialias_cbmi.isSelected() );
1302 options.setBackgroundColorGradient( ( _background_gradient_cbmi != null )
1303 && _background_gradient_cbmi.isSelected() );
1304 options.setShowDomainLabels( ( _show_domain_labels != null ) && _show_domain_labels.isSelected() );
1305 options.setShowAnnotationRefSource( ( _show_annotation_ref_source != null )
1306 && _show_annotation_ref_source.isSelected() );
1307 options.setAbbreviateScientificTaxonNames( ( _abbreviate_scientific_names != null )
1308 && _abbreviate_scientific_names.isSelected() );
1309 options.setColorLabelsSameAsParentBranch( ( _color_labels_same_as_parent_branch != null )
1310 && _color_labels_same_as_parent_branch.isSelected() );
1311 options.setShowDefaultNodeShapesInternal( ( _show_default_node_shapes_internal_cbmi != null )
1312 && _show_default_node_shapes_internal_cbmi.isSelected() );
1313 options.setShowDefaultNodeShapesExternal( ( _show_default_node_shapes_external_cbmi != null )
1314 && _show_default_node_shapes_external_cbmi.isSelected() );
1315 options.setShowDefaultNodeShapesForMarkedNodes( ( _show_default_node_shapes_for_marked_cbmi != null )
1316 && _show_default_node_shapes_for_marked_cbmi.isSelected() );
1317 if ( ( _non_lined_up_cladograms_rbmi != null ) && ( _non_lined_up_cladograms_rbmi.isSelected() ) ) {
1318 options.setCladogramType( CLADOGRAM_TYPE.NON_LINED_UP );
1320 else if ( ( _uniform_cladograms_rbmi != null ) && ( _uniform_cladograms_rbmi.isSelected() ) ) {
1321 options.setCladogramType( CLADOGRAM_TYPE.TOTAL_NODE_SUM_DEP );
1323 else if ( ( _ext_node_dependent_cladogram_rbmi != null ) && ( _ext_node_dependent_cladogram_rbmi.isSelected() ) ) {
1324 options.setCladogramType( CLADOGRAM_TYPE.EXT_NODE_SUM_DEP );
1326 options.setSearchCaseSensitive( ( _search_case_senstive_cbmi != null )
1327 && _search_case_senstive_cbmi.isSelected() );
1328 if ( ( _show_scale_cbmi != null ) && _show_scale_cbmi.isEnabled() ) {
1329 options.setShowScale( _show_scale_cbmi.isSelected() );
1331 if ( _label_direction_cbmi != null ) {
1332 if ( _label_direction_cbmi.isSelected() ) {
1333 options.setNodeLabelDirection( NODE_LABEL_DIRECTION.RADIAL );
1336 options.setNodeLabelDirection( NODE_LABEL_DIRECTION.HORIZONTAL );
1339 options.setShowOverview( ( _show_overview_cbmi != null ) && _show_overview_cbmi.isSelected() );
1340 options.setShowConfidenceStddev( ( _show_confidence_stddev_cbmi != null )
1341 && _show_confidence_stddev_cbmi.isSelected() );
1342 options.setMatchWholeTermsOnly( ( _search_whole_words_only_cbmi != null )
1343 && _search_whole_words_only_cbmi.isSelected() );
1344 options.setInverseSearchResult( ( _inverse_search_result_cbmi != null )
1345 && _inverse_search_result_cbmi.isSelected() );
1346 if ( ( _rectangular_type_cbmi != null ) && _rectangular_type_cbmi.isSelected() ) {
1347 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR );
1349 else if ( ( _triangular_type_cbmi != null ) && _triangular_type_cbmi.isSelected() ) {
1350 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.TRIANGULAR );
1352 else if ( ( _curved_type_cbmi != null ) && _curved_type_cbmi.isSelected() ) {
1353 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CURVED );
1355 else if ( ( _convex_type_cbmi != null ) && _convex_type_cbmi.isSelected() ) {
1356 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CONVEX );
1358 else if ( ( _euro_type_cbmi != null ) && _euro_type_cbmi.isSelected() ) {
1359 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE );
1361 else if ( ( _rounded_type_cbmi != null ) && _rounded_type_cbmi.isSelected() ) {
1362 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.ROUNDED );
1364 else if ( ( _unrooted_type_cbmi != null ) && _unrooted_type_cbmi.isSelected() ) {
1365 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.UNROOTED );
1367 else if ( ( _circular_type_cbmi != null ) && _circular_type_cbmi.isSelected() ) {
1368 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CIRCULAR );
1370 if ( ( _color_by_taxonomic_group_cbmi != null ) && _color_by_taxonomic_group_cbmi.isEnabled() ) {
1371 options.setColorByTaxonomicGroup( _color_by_taxonomic_group_cbmi.isSelected() );
1373 if ( ( _right_line_up_domains_cbmi != null ) && _right_line_up_domains_cbmi.isEnabled() ) {
1374 options.setRightLineUpDomains( _right_line_up_domains_cbmi.isSelected() );
1376 if ( ( _line_up_renderable_data_cbmi != null ) && _line_up_renderable_data_cbmi.isEnabled() ) {
1377 options.setLineUpRendarableNodeData( _line_up_renderable_data_cbmi.isSelected() );
1381 void updateTypeCheckboxes( final Options options, final Object o ) {
1382 setTypeMenuToAllUnselected();
1383 ( ( JCheckBoxMenuItem ) o ).setSelected( true );
1386 void viewAsNexus() {
1387 if ( ( getMainPanel().getCurrentPhylogeny() != null ) && !getMainPanel().getCurrentPhylogeny().isEmpty() ) {
1388 String title = "Nexus";
1389 if ( !ForesterUtil.isEmpty( getMainPanel().getCurrentPhylogeny().getName() ) ) {
1390 title = "\"" + getMainPanel().getCurrentPhylogeny().getName() + "\" in " + title;
1392 showTextFrame( getMainPanel().getCurrentPhylogeny().toNexus( getOptions()
1393 .getNhConversionSupportValueStyle() ),
1399 if ( ( getMainPanel().getCurrentPhylogeny() != null ) && !getMainPanel().getCurrentPhylogeny().isEmpty() ) {
1400 String title = "New Hampshire";
1401 if ( !ForesterUtil.isEmpty( getMainPanel().getCurrentPhylogeny().getName() ) ) {
1402 title = "\"" + getMainPanel().getCurrentPhylogeny().getName() + "\" in " + title;
1404 showTextFrame( getMainPanel().getCurrentPhylogeny().toNewHampshire( getOptions()
1405 .getNhConversionSupportValueStyle() ),
1411 if ( ( getMainPanel().getCurrentPhylogeny() != null ) && !getMainPanel().getCurrentPhylogeny().isEmpty() ) {
1412 String title = "phyloXML";
1413 if ( !ForesterUtil.isEmpty( getMainPanel().getCurrentPhylogeny().getName() ) ) {
1414 title = "\"" + getMainPanel().getCurrentPhylogeny().getName() + "\" in " + title;
1416 showTextFrame( getMainPanel().getCurrentPhylogeny().toPhyloXML( 0 ), title );
1420 private void chooseFont() {
1421 final FontChooser fc = new FontChooser();
1422 fc.setFont( getMainPanel().getTreeFontSet().getLargeFont() );
1423 fc.showDialog( this, "Select the Base Font" );
1424 getMainPanel().getTreeFontSet().setBaseFont( fc.getFont() );
1427 private void chooseMinimalConfidence() {
1428 final String s = ( String ) JOptionPane
1429 .showInputDialog( this,
1430 "Please the minimum for confidence values to be displayed.\n" + "[current value: "
1431 + getOptions().getMinConfidenceValue() + "]\n",
1432 "Minimal Confidence Value",
1433 JOptionPane.QUESTION_MESSAGE,
1436 getOptions().getMinConfidenceValue() );
1437 if ( !ForesterUtil.isEmpty( s ) ) {
1438 boolean success = true;
1440 final String m_str = s.trim();
1441 if ( !ForesterUtil.isEmpty( m_str ) ) {
1443 m = Double.parseDouble( m_str );
1445 catch ( final Exception ex ) {
1452 if ( success && ( m >= 0.0 ) ) {
1453 getOptions().setMinConfidenceValue( m );
1458 private void customizeRadioButtonMenuItem( final JRadioButtonMenuItem item, final boolean is_selected ) {
1459 if ( item != null ) {
1460 item.setFont( MainFrame.menu_font );
1461 if ( !getConfiguration().isUseNativeUI() ) {
1462 item.setBackground( getConfiguration().getGuiMenuBackgroundColor() );
1463 item.setForeground( getConfiguration().getGuiMenuTextColor() );
1465 item.setSelected( is_selected );
1466 item.addActionListener( this );
1470 MainPanel getMainPanel() {
1474 private Phylogeny getSpeciesTree() {
1475 return _species_tree;
1478 private boolean isScreenAntialias() {
1482 private void removeBranchColors() {
1483 if ( getMainPanel().getCurrentPhylogeny() != null ) {
1484 AptxUtil.removeBranchColors( getMainPanel().getCurrentPhylogeny() );
1488 private void removeVisualStyles() {
1489 if ( getMainPanel().getCurrentPhylogeny() != null ) {
1490 AptxUtil.removeVisualStyles( getMainPanel().getCurrentPhylogeny() );
1494 private void setMainPanel( final MainPanelApplets main_panel ) {
1495 _mainpanel = main_panel;
1498 private void setSpeciesTree( final Phylogeny species_tree ) {
1499 _species_tree = species_tree;
1502 private void setupUI() {
1504 if ( getConfiguration().isUseNativeUI() ) {
1505 UIManager.setLookAndFeel( UIManager.getSystemLookAndFeelClassName() );
1508 UIManager.setLookAndFeel( UIManager.getCrossPlatformLookAndFeelClassName() );
1511 catch ( final UnsupportedLookAndFeelException e ) {
1512 AptxUtil.dieWithSystemError( "UnsupportedLookAndFeelException: " + e.toString() );
1514 catch ( final ClassNotFoundException e ) {
1515 AptxUtil.dieWithSystemError( "ClassNotFoundException: " + e.toString() );
1517 catch ( final InstantiationException e ) {
1518 AptxUtil.dieWithSystemError( "InstantiationException: " + e.toString() );
1520 catch ( final IllegalAccessException e ) {
1521 AptxUtil.dieWithSystemError( "IllegalAccessException: " + e.toString() );
1523 catch ( final Exception e ) {
1524 AptxUtil.dieWithSystemError( e.toString() );
1528 static void setupScreenTextAntialias( final List<TreePanel> treepanels, final boolean antialias ) {
1529 for( final TreePanel tree_panel : treepanels ) {
1530 tree_panel.setTextAntialias();