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;
137 public void actionPerformed( final ActionEvent e ) {
138 final Object o = e.getSource();
139 if ( o == _midpoint_root_item ) {
140 getMainPanel().getCurrentTreePanel().midpointRoot();
142 else if ( o == _gsdi_item ) {
143 if ( isSubtreeDisplayed() ) {
148 else if ( o == _gsdir_item ) {
149 if ( isSubtreeDisplayed() ) {
154 else if ( o == _taxcolor_item ) {
155 getMainPanel().getCurrentTreePanel().taxColor();
157 else if ( o == _confcolor_item ) {
158 getMainPanel().getCurrentTreePanel().confColor();
160 else if ( o == _collapse_species_specific_subtrees ) {
161 if ( getCurrentTreePanel() != null ) {
162 getCurrentTreePanel().collapseSpeciesSpecificSubtrees();
165 else if ( o == _remove_branch_color_item ) {
166 removeBranchColors();
168 else if ( o == _remove_visual_styles_item ) {
169 removeVisualStyles();
171 else if ( o == _switch_colors_mi ) {
174 else if ( o == _display_basic_information_item ) {
175 displayBasicInformation();
177 else if ( o == _view_as_NH_item ) {
180 else if ( o == _view_as_XML_item ) {
183 else if ( o == _view_as_nexus_item ) {
186 else if ( o == _super_tiny_fonts_mi ) {
187 if ( getCurrentTreePanel() != null ) {
188 getCurrentTreePanel().setSuperTinyFonts();
189 getCurrentTreePanel().repaint();
192 else if ( o == _tiny_fonts_mi ) {
193 if ( getCurrentTreePanel() != null ) {
194 getCurrentTreePanel().setTinyFonts();
195 getCurrentTreePanel().repaint();
198 else if ( o == _small_fonts_mi ) {
199 if ( getCurrentTreePanel() != null ) {
200 getCurrentTreePanel().setSmallFonts();
201 getCurrentTreePanel().repaint();
204 else if ( o == _medium_fonts_mi ) {
205 if ( getCurrentTreePanel() != null ) {
206 getCurrentTreePanel().setMediumFonts();
207 getCurrentTreePanel().repaint();
210 else if ( o == _large_fonts_mi ) {
211 if ( getCurrentTreePanel() != null ) {
212 getCurrentTreePanel().setLargeFonts();
213 getCurrentTreePanel().repaint();
216 else if ( o == _choose_font_mi ) {
219 else if ( o == _choose_minimal_confidence_mi ) {
220 chooseMinimalConfidence();
222 else if ( o == _choose_node_size_mi ) {
223 MainFrame.chooseNodeSize( getOptions(), this );
225 else if ( o == _overview_placment_mi ) {
226 MainFrame.cycleOverview( getOptions(), getCurrentTreePanel() );
228 else if ( o == _cycle_node_fill_mi ) {
229 MainFrame.cycleNodeFill( getOptions(), getCurrentTreePanel() );
231 else if ( o == _cycle_node_shape_mi ) {
232 MainFrame.cycleNodeShape( getOptions(), getCurrentTreePanel() );
234 else if ( o == _non_lined_up_cladograms_rbmi ) {
235 updateOptions( getOptions() );
236 _mainpanel.getControlPanel().showWhole();
238 else if ( o == _uniform_cladograms_rbmi ) {
239 updateOptions( getOptions() );
240 _mainpanel.getControlPanel().showWhole();
242 else if ( o == _ext_node_dependent_cladogram_rbmi ) {
243 updateOptions( getOptions() );
244 _mainpanel.getControlPanel().showWhole();
246 else if ( o == _search_case_senstive_cbmi ) {
247 updateOptions( getOptions() );
248 getMainPanel().getControlPanel().search0();
249 getMainPanel().getControlPanel().search1();
251 else if ( o == _search_whole_words_only_cbmi ) {
252 updateOptions( getOptions() );
253 getMainPanel().getControlPanel().search0();
254 getMainPanel().getControlPanel().search1();
256 else if ( o == _inverse_search_result_cbmi ) {
257 updateOptions( getOptions() );
258 getMainPanel().getControlPanel().search0();
259 getMainPanel().getControlPanel().search1();
261 else if ( o == _show_scale_cbmi ) {
262 updateOptions( getOptions() );
264 else if ( o == _show_branch_length_values_cbmi ) {
265 updateOptions( getOptions() );
267 else if ( o == _show_confidence_stddev_cbmi ) {
268 updateOptions( getOptions() );
270 else if ( o == _label_direction_cbmi ) {
271 updateOptions( getOptions() );
273 else if ( o == _abbreviate_scientific_names ) {
274 updateOptions( getOptions() );
276 else if ( o == _show_overview_cbmi ) {
277 updateOptions( getOptions() );
278 if ( getCurrentTreePanel() != null ) {
279 getCurrentTreePanel().updateOvSizes();
282 else if ( ( o == _rectangular_type_cbmi ) || ( o == _triangular_type_cbmi ) || ( o == _curved_type_cbmi )
283 || ( o == _convex_type_cbmi ) || ( o == _rounded_type_cbmi ) || ( o == _euro_type_cbmi )
284 || ( o == _unrooted_type_cbmi ) || ( o == _circular_type_cbmi ) ) {
287 else if ( o == _screen_antialias_cbmi ) {
288 updateOptions( getOptions() );
289 setupScreenTextAntialias( getMainPanel().getTreePanels(), isScreenAntialias() );
291 else if ( o == _background_gradient_cbmi ) {
292 updateOptions( getOptions() );
294 else if ( o == _show_domain_labels ) {
295 updateOptions( getOptions() );
297 else if ( o == _color_labels_same_as_parent_branch ) {
298 updateOptions( getOptions() );
300 else if ( o == _show_default_node_shapes_internal_cbmi ) {
301 updateOptions( getOptions() );
303 else if ( o == _show_default_node_shapes_external_cbmi ) {
304 updateOptions( getOptions() );
306 else if ( o == _about_item ) {
309 else if ( o == _help_item ) {
312 else if ( o == _website_item ) {
314 AptxUtil.openWebsite( Constants.APTX_WEB_SITE, true, this );
316 catch ( final IOException e1 ) {
317 ForesterUtil.printErrorMessage( Constants.PRG_NAME, e1.toString() );
320 else if ( o == _phyloxml_website_item ) {
322 AptxUtil.openWebsite( Constants.PHYLOXML_WEB_SITE, true, this );
324 catch ( final IOException e1 ) {
325 ForesterUtil.printErrorMessage( Constants.PRG_NAME, e1.toString() );
328 else if ( o == _aptx_ref_item ) {
330 AptxUtil.openWebsite( Constants.APTX_REFERENCE_URL, true, this );
332 catch ( final IOException e1 ) {
333 ForesterUtil.printErrorMessage( Constants.PRG_NAME, e1.toString() );
336 else if ( o == _phyloxml_ref_item ) {
338 AptxUtil.openWebsite( Constants.PHYLOXML_REFERENCE_URL, true, this );
340 catch ( final IOException e1 ) {
341 ForesterUtil.printErrorMessage( Constants.PRG_NAME, e1.toString() );
344 else if ( o == _color_by_taxonomic_group_cbmi ) {
345 updateOptions( getOptions() );
351 public void destroy() {
352 AptxUtil.printAppletMessage( NAME, "going to be destroyed " );
353 removeAllTextFrames();
354 if ( getMainPanel() != null ) {
355 getMainPanel().terminate();
360 * This method returns the current external node data which
361 * has been selected by the user by clicking the "Return ..."
362 * menu item. This method is expected to be called from Javascript or
365 * @return current external node data as String
367 public String getCurrentExternalNodesDataBuffer() {
368 return getCurrentTreePanel().getCurrentExternalNodesDataBufferAsString();
371 public int getCurrentExternalNodesDataBufferChangeCounter() {
372 return getCurrentTreePanel().getCurrentExternalNodesDataBufferChangeCounter();
375 public int getCurrentExternalNodesDataBufferLength() {
376 return getCurrentTreePanel().getCurrentExternalNodesDataBufferAsString().length();
380 * This method returns the current phylogeny as a string in the chosen format
382 * @param format must be NH, NHX, NEXUS or PHYLOXML
383 * @return the phylogeny string
384 * @author Herve Menager
386 public String getCurrentPhylogeny( final String format ) {
387 removeAllTextFrames();
388 if ( ( getMainPanel().getCurrentPhylogeny() == null ) || getMainPanel().getCurrentPhylogeny().isEmpty()
389 || ( getMainPanel().getCurrentPhylogeny().getNumberOfExternalNodes() > 10000 ) ) {
392 switch ( ForesterConstants.PhylogeneticTreeFormats.valueOf( format ) ) {
394 return getMainPanel().getCurrentPhylogeny().toNewHampshire();
396 return getMainPanel().getCurrentPhylogeny().toNewHampshireX();
398 return getMainPanel().getCurrentPhylogeny().toNexus();
400 return getMainPanel().getCurrentPhylogeny().toPhyloXML( -1 );
408 * This method returns a view of the current phylogeny in a chosen
409 * graphics format, base64-encoded in a string so that in can be used
412 * @param format must be GraphicsExportType (gif, jpg, pdf, png, tif, bmp)
413 * @return the phylogeny string
414 * @author Herve Menager
416 public String getCurrentPhylogenyGraphicsAsBase64EncodedString( final String format ) {
417 final ByteArrayOutputStream baos = new ByteArrayOutputStream();
419 AptxUtil.writePhylogenyToGraphicsByteArrayOutputStream( baos,
420 _mainpanel.getWidth(),
421 _mainpanel.getHeight(),
422 getCurrentTreePanel(),
423 getCurrentTreePanel().getControlPanel(),
424 GraphicsExportType.valueOf( format ),
427 catch ( final IOException ioe ) {
428 ForesterUtil.printErrorMessage( NAME, ioe.toString() );
429 ioe.printStackTrace();
430 JOptionPane.showMessageDialog( this,
431 NAME + ": Failed to generate graphics: " + "\nException: " + ioe,
432 "Failed to generate graphics",
433 JOptionPane.ERROR_MESSAGE );
436 final byte[] bytes = baos.toByteArray();
437 final String dataImg = Base64.encodeBase64String( bytes );
441 public Options getOptions() {
447 final String config_filename = getParameter( Constants.APPLET_PARAM_NAME_FOR_CONFIG_FILE_URL );
448 AptxUtil.printAppletMessage( NAME, "URL for configuration file is: " + config_filename );
449 final Configuration configuration = new Configuration( config_filename, true, true, true );
450 setConfiguration( configuration );
451 setOptions( Options.createInstance( configuration ) );
453 final String tree_url_str = getParameter( Constants.APPLET_PARAM_NAME_FOR_URL_OF_TREE_TO_LOAD );
454 if ( ForesterUtil.isEmpty( tree_url_str ) ) {
455 ForesterUtil.printErrorMessage( NAME, "could not get tree URL from "
456 + Constants.APPLET_PARAM_NAME_FOR_URL_OF_TREE_TO_LOAD );
457 JOptionPane.showMessageDialog( this, NAME + ": could not get tree URL from "
458 + Constants.APPLET_PARAM_NAME_FOR_URL_OF_TREE_TO_LOAD, "Failed get URL", JOptionPane.ERROR_MESSAGE );
461 AptxUtil.printAppletMessage( NAME, "URL for phylogenies is " + tree_url_str );
462 // Get URL to tree file
465 phys_url = new URL( tree_url_str );
467 catch ( final Exception e ) {
468 ForesterUtil.printErrorMessage( NAME, "error: " + e );
470 JOptionPane.showMessageDialog( this, NAME + ": Could not create URL from: \"" + tree_url_str
471 + "\"\nException: " + e, "Failed to create URL", JOptionPane.ERROR_MESSAGE );
473 if ( phys_url == null ) {
474 ForesterUtil.printErrorMessage( NAME, "failed to get tree URL from "
475 + Constants.APPLET_PARAM_NAME_FOR_URL_OF_TREE_TO_LOAD );
476 JOptionPane.showMessageDialog( this,
477 NAME + ": Could not create URL from: \"" + tree_url_str,
478 "Failed to create URL",
479 JOptionPane.ERROR_MESSAGE );
482 // Load the tree from URL
483 Phylogeny[] phys = null;
485 phys = AptxUtil.readPhylogeniesFromUrl( phys_url,
486 getConfiguration().isValidatePhyloXmlAgainstSchema(),
487 getConfiguration().isReplaceUnderscoresInNhParsing(),
488 getConfiguration().isInternalNumberAreConfidenceForNhParsing(),
489 getConfiguration().getTaxonomyExtraction(),
490 getConfiguration().isMidpointReroot() );
492 catch ( final Exception e ) {
493 ForesterUtil.printErrorMessage( NAME, e.toString() );
495 JOptionPane.showMessageDialog( this,
496 NAME + ": Failed to read phylogenies: " + "\nException: " + e,
497 "Failed to read phylogenies",
498 JOptionPane.ERROR_MESSAGE );
500 if ( phys == null ) {
501 ForesterUtil.printErrorMessage( NAME, "phylogenies from [" + phys_url + "] are null" );
502 JOptionPane.showMessageDialog( this,
503 NAME + ": phylogenies from [" + phys_url + "] are null",
504 "Failed to read phylogenies",
505 JOptionPane.ERROR_MESSAGE );
508 else if ( phys.length < 1 ) {
509 ForesterUtil.printErrorMessage( NAME, "phylogenies from [" + phys_url + "] are empty" );
510 JOptionPane.showMessageDialog( this,
511 NAME + ": phylogenies from [" + phys_url + "] are empty",
512 "Failed to read phylogenies",
513 JOptionPane.ERROR_MESSAGE );
517 AptxUtil.printAppletMessage( NAME, "loaded " + phys.length + " phylogenies from: " + phys_url );
520 final String species_tree_url_str = getParameter( Constants.APPLET_PARAM_NAME_FOR_URL_OF_SPECIES_TREE_TO_LOAD );
521 if ( !ForesterUtil.isEmpty( species_tree_url_str ) ) {
522 AptxUtil.printAppletMessage( NAME, "URL of species tree to load: \"" + species_tree_url_str + "\"" );
523 Phylogeny[] species_trees = null;
525 final URL species_tree_url = new URL( species_tree_url_str );
526 species_trees = AptxUtil.readPhylogeniesFromUrl( species_tree_url,
527 configuration.isValidatePhyloXmlAgainstSchema(),
528 configuration.isReplaceUnderscoresInNhParsing(),
530 TAXONOMY_EXTRACTION.NO,
533 catch ( final IOException e ) {
534 ForesterUtil.printErrorMessage( NAME, "could not read species tree from [" + species_tree_url_str
536 JOptionPane.showMessageDialog( this, NAME + ": could not read species tree from ["
537 + species_tree_url_str + "]", "Failed to read species tree", JOptionPane.ERROR_MESSAGE );
539 if ( ( species_trees != null ) && ( species_trees.length > 0 ) ) {
540 AptxUtil.printAppletMessage( NAME, "successfully read species tree" );
541 if ( species_trees[ 0 ].isEmpty() ) {
542 ForesterUtil.printErrorMessage( NAME, "species tree is empty" );
544 else if ( !species_trees[ 0 ].isRooted() ) {
545 ForesterUtil.printErrorMessage( NAME, "species tree is not rooted" );
548 setSpeciesTree( species_trees[ 0 ] );
549 AptxUtil.printAppletMessage( NAME, "species tree OK" );
555 setMainPanel( new MainPanelApplets( getConfiguration(), this ) );
556 _jmenubar = new JMenuBar();
557 if ( !getConfiguration().isHideControlPanelAndMenubar() ) {
558 if ( !getConfiguration().isUseNativeUI() ) {
559 _jmenubar.setBackground( getConfiguration().getGuiMenuBackgroundColor() );
561 if ( getSpeciesTree() != null ) {
570 setJMenuBar( _jmenubar );
572 final Container contentpane = getContentPane();
573 contentpane.setLayout( new BorderLayout() );
574 contentpane.add( getMainPanel(), BorderLayout.CENTER );
575 addComponentListener( new ComponentAdapter() {
578 public void componentResized( final ComponentEvent e ) {
579 if ( getMainPanel().getCurrentTreePanel() != null ) {
580 getMainPanel().getCurrentTreePanel().calcParametersForPainting( getMainPanel()
581 .getCurrentTreePanel()
584 .getCurrentTreePanel()
587 .isAllowFontSizeChange() );
591 if ( getConfiguration().isUseTabbedDisplay() ) {
592 AptxUtil.printAppletMessage( NAME, "using tabbed display" );
593 AptxUtil.addPhylogeniesToTabs( phys,
594 new File( phys_url.getFile() ).getName(),
600 AptxUtil.printAppletMessage( NAME, "not using tabbed display" );
601 if ( getSpeciesTree() != null ) {
602 AptxUtil.printAppletMessage( NAME,
603 "Warning: gsdi (gene duplication inference) only available tabbed display" );
605 AptxUtil.addPhylogenyToPanel( phys, getConfiguration(), getMainPanel() );
609 getMainPanel().getControlPanel().showWholeAll();
610 getMainPanel().getControlPanel().showWhole();
612 getCurrentTreePanel().getControlPanel().getSequenceRelationTypeBox().removeAllItems();
613 for( final SequenceRelation.SEQUENCE_RELATION_TYPE type : getMainPanel().getCurrentPhylogeny()
614 .getRelevantSequenceRelationTypes() ) {
615 getCurrentTreePanel().getControlPanel().getSequenceRelationTypeBox().addItem( type );
617 final String default_relation = getParameter( Constants.APPLET_PARAM_NAME_FOR_DEFAULT_SEQUENCE_RELATION_TYPE );
618 if ( default_relation != null ) {
619 getCurrentTreePanel().getControlPanel().getSequenceRelationTypeBox().setSelectedItem( default_relation );
621 final String default_sequence = getParameter( Constants.APPLET_PARAM_NAME_FOR_DEFAULT_QUERY_SEQUENCE );
622 if ( default_sequence != null ) {
623 getCurrentTreePanel().getControlPanel().getSequenceRelationBox().setSelectedItem( default_sequence );
627 AptxUtil.printAppletMessage( NAME, "successfully initialized" );
631 public void showTextFrame( final String s, final String title ) {
633 _textframes.addLast( TextFrame.instantiate( s, title, _textframes ) );
637 public void start() {
638 if ( getMainPanel() != null ) {
639 getMainPanel().validate();
642 requestFocusInWindow();
644 AptxUtil.printAppletMessage( NAME, "started" );
647 void buildAnalysisMenu() {
648 _analysis_menu = MainFrame.createMenu( "Analysis", getConfiguration() );
649 _analysis_menu.add( _gsdi_item = new JMenuItem( "GSDI (Generalized Speciation Duplication Inference)" ) );
650 _analysis_menu.add( _gsdir_item = new JMenuItem( "GSDIR (GSDI with re-rooting)" ) );
651 customizeJMenuItem( _gsdi_item );
652 customizeJMenuItem( _gsdir_item );
653 // _analysis_menu.addSeparator();
654 // _analysis_menu.add( _lineage_inference = new JMenuItem( INFER_ANCESTOR_TAXONOMIES ) );
655 // customizeJMenuItem( _lineage_inference );
656 // _lineage_inference.setToolTipText( "Inference of ancestor taxonomies/lineages" );
657 _jmenubar.add( _analysis_menu );
660 void buildFontSizeMenu() {
661 _font_size_menu = MainFrame.createMenu( MainFrame.FONT_SIZE_MENU_LABEL, getConfiguration() );
662 _font_size_menu.add( _super_tiny_fonts_mi = new JMenuItem( "Super tiny fonts" ) );
663 _font_size_menu.add( _tiny_fonts_mi = new JMenuItem( "Tiny fonts" ) );
664 _font_size_menu.add( _small_fonts_mi = new JMenuItem( "Small fonts" ) );
665 _font_size_menu.add( _medium_fonts_mi = new JMenuItem( "Medium fonts" ) );
666 _font_size_menu.add( _large_fonts_mi = new JMenuItem( "Large fonts" ) );
667 customizeJMenuItem( _super_tiny_fonts_mi );
668 customizeJMenuItem( _tiny_fonts_mi );
669 customizeJMenuItem( _small_fonts_mi );
670 customizeJMenuItem( _medium_fonts_mi );
671 customizeJMenuItem( _large_fonts_mi );
672 _jmenubar.add( _font_size_menu );
675 void buildHelpMenu() {
676 _help_jmenu = MainFrame.createMenu( "Help", getConfiguration() );
677 _help_jmenu.add( _help_item = new JMenuItem( "Help" ) );
678 _help_jmenu.add( _website_item = new JMenuItem( "Archaeopteryx Home" ) );
679 _aptx_ref_item = new JMenuItem( "Archaeopteryx Reference" );
680 _help_jmenu.add( _phyloxml_website_item = new JMenuItem( "phyloXML Home" ) );
681 _help_jmenu.add( _phyloxml_ref_item = new JMenuItem( "phyloXML Reference" ) );
682 _help_jmenu.addSeparator();
683 _help_jmenu.add( _about_item = new JMenuItem( "About" ) );
684 customizeJMenuItem( _help_item );
685 customizeJMenuItem( _website_item );
686 customizeJMenuItem( _phyloxml_website_item );
687 customizeJMenuItem( _aptx_ref_item );
688 customizeJMenuItem( _phyloxml_ref_item );
689 customizeJMenuItem( _about_item );
690 _phyloxml_ref_item.setToolTipText( MainFrame.PHYLOXML_REF_TOOL_TIP );
691 _aptx_ref_item.setToolTipText( MainFrame.APTX_REF_TOOL_TIP );
692 _jmenubar.add( _help_jmenu );
695 void buildOptionsMenu() {
696 _options_jmenu = MainFrame.createMenu( MainFrame.OPTIONS_HEADER, getConfiguration() );
697 _options_jmenu.addChangeListener( new ChangeListener() {
700 public void stateChanged( final ChangeEvent e ) {
701 MainFrame.setOvPlacementColorChooseMenuItem( _overview_placment_mi, getOptions() );
702 MainFrame.setTextColorChooseMenuItem( _switch_colors_mi, getCurrentTreePanel() );
704 .setTextMinSupportMenuItem( _choose_minimal_confidence_mi, getOptions(), getCurrentTreePanel() );
705 MainFrame.setTextForFontChooserMenuItem( _choose_font_mi, MainFrame
706 .createCurrentFontDesc( getMainPanel().getTreeFontSet() ) );
707 MainFrame.updateOptionsMenuDependingOnPhylogenyType( getMainPanel(),
709 _show_branch_length_values_cbmi,
710 _non_lined_up_cladograms_rbmi,
711 _uniform_cladograms_rbmi,
712 _ext_node_dependent_cladogram_rbmi,
713 _label_direction_cbmi );
714 MainFrame.setCycleNodeFillMenuItem( _cycle_node_fill_mi, getOptions() );
715 MainFrame.setCycleNodeShapeMenuItem( _cycle_node_shape_mi, getOptions() );
716 MainFrame.setTextNodeSizeMenuItem( _choose_node_size_mi, getOptions() );
719 _options_jmenu.add( MainFrame.customizeMenuItemAsLabel( new JMenuItem( MainFrame.DISPLAY_SUBHEADER ),
720 getConfiguration() ) );
722 .add( _ext_node_dependent_cladogram_rbmi = new JRadioButtonMenuItem( MainFrame.NONUNIFORM_CLADOGRAMS_LABEL ) );
723 _options_jmenu.add( _uniform_cladograms_rbmi = new JRadioButtonMenuItem( MainFrame.UNIFORM_CLADOGRAMS_LABEL ) );
725 .add( _non_lined_up_cladograms_rbmi = new JRadioButtonMenuItem( MainFrame.NON_LINED_UP_CLADOGRAMS_LABEL ) );
726 _radio_group_1 = new ButtonGroup();
727 _radio_group_1.add( _ext_node_dependent_cladogram_rbmi );
728 _radio_group_1.add( _uniform_cladograms_rbmi );
729 _radio_group_1.add( _non_lined_up_cladograms_rbmi );
731 _options_jmenu.add( _show_overview_cbmi = new JCheckBoxMenuItem( MainFrame.SHOW_OVERVIEW_LABEL ) );
732 _options_jmenu.add( _show_scale_cbmi = new JCheckBoxMenuItem( MainFrame.DISPLAY_SCALE_LABEL ) );
734 .add( _show_branch_length_values_cbmi = new JCheckBoxMenuItem( MainFrame.DISPLAY_BRANCH_LENGTH_VALUES_LABEL ) );
736 .add( _show_default_node_shapes_internal_cbmi = new JCheckBoxMenuItem( MainFrame.DISPLAY_NODE_BOXES_LABEL_INT ) );
738 .add( _show_default_node_shapes_external_cbmi = new JCheckBoxMenuItem( MainFrame.DISPLAY_NODE_BOXES_LABEL_EXT ) );
739 if ( getConfiguration().doDisplayOption( Configuration.show_domain_architectures ) ) {
740 _options_jmenu.add( _show_domain_labels = new JCheckBoxMenuItem( MainFrame.SHOW_DOMAIN_LABELS_LABEL ) );
742 _options_jmenu.add( _show_annotation_ref_source = new JCheckBoxMenuItem( MainFrame.SHOW_ANN_REF_SOURCE_LABEL ) );
743 _options_jmenu.add( _show_confidence_stddev_cbmi = new JCheckBoxMenuItem( MainFrame.SHOW_CONF_STDDEV_LABEL ) );
745 .add( _color_by_taxonomic_group_cbmi = new JCheckBoxMenuItem( MainFrame.COLOR_BY_TAXONOMIC_GROUP ) );
747 .add( _color_labels_same_as_parent_branch = new JCheckBoxMenuItem( MainFrame.COLOR_LABELS_LABEL ) );
748 _color_labels_same_as_parent_branch.setToolTipText( MainFrame.COLOR_LABELS_TIP );
749 _options_jmenu.add( _abbreviate_scientific_names = new JCheckBoxMenuItem( MainFrame.ABBREV_SN_LABEL ) );
750 _options_jmenu.add( _label_direction_cbmi = new JCheckBoxMenuItem( MainFrame.LABEL_DIRECTION_LABEL ) );
751 _label_direction_cbmi.setToolTipText( MainFrame.LABEL_DIRECTION_TIP );
752 _options_jmenu.add( _screen_antialias_cbmi = new JCheckBoxMenuItem( MainFrame.SCREEN_ANTIALIAS_LABEL ) );
753 _options_jmenu.add( _background_gradient_cbmi = new JCheckBoxMenuItem( MainFrame.BG_GRAD_LABEL ) );
754 _options_jmenu.add( _cycle_node_shape_mi = new JMenuItem( MainFrame.CYCLE_NODE_SHAPE_LABEL ) );
755 _options_jmenu.add( _cycle_node_fill_mi = new JMenuItem( MainFrame.CYCLE_NODE_FILL_LABEL ) );
756 _options_jmenu.add( _choose_node_size_mi = new JMenuItem( MainFrame.CHOOSE_NODE_SIZE_LABEL ) );
757 _options_jmenu.add( _choose_minimal_confidence_mi = new JMenuItem( "" ) );
758 _options_jmenu.add( _overview_placment_mi = new JMenuItem( "" ) );
759 _options_jmenu.add( _switch_colors_mi = new JMenuItem( "" ) );
760 _options_jmenu.add( _choose_font_mi = new JMenuItem( "" ) );
762 _options_jmenu.addSeparator();
763 _options_jmenu.add( MainFrame.customizeMenuItemAsLabel( new JMenuItem( MainFrame.SEARCH_SUBHEADER ),
764 getConfiguration() ) );
766 .add( _search_case_senstive_cbmi = new JCheckBoxMenuItem( MainFrame.SEARCH_CASE_SENSITIVE_LABEL ) );
767 _options_jmenu.add( _search_whole_words_only_cbmi = new JCheckBoxMenuItem( MainFrame.SEARCH_TERMS_ONLY_LABEL ) );
769 .add( _inverse_search_result_cbmi = new JCheckBoxMenuItem( MainFrame.INVERSE_SEARCH_RESULT_LABEL ) );
770 customizeJMenuItem( _choose_font_mi );
771 customizeJMenuItem( _choose_minimal_confidence_mi );
772 customizeJMenuItem( _switch_colors_mi );
773 customizeJMenuItem( _overview_placment_mi );
774 customizeCheckBoxMenuItem( _color_by_taxonomic_group_cbmi, getOptions().isColorByTaxonomicGroup() );
775 customizeCheckBoxMenuItem( _label_direction_cbmi,
776 getOptions().getNodeLabelDirection() == NODE_LABEL_DIRECTION.RADIAL );
777 customizeCheckBoxMenuItem( _screen_antialias_cbmi, getOptions().isAntialiasScreen() );
778 customizeCheckBoxMenuItem( _background_gradient_cbmi, getOptions().isBackgroundColorGradient() );
779 customizeCheckBoxMenuItem( _show_domain_labels, getOptions().isShowDomainLabels() );
780 customizeCheckBoxMenuItem( _show_annotation_ref_source, getOptions().isShowAnnotationRefSource() );
781 customizeCheckBoxMenuItem( _abbreviate_scientific_names, getOptions().isAbbreviateScientificTaxonNames() );
782 customizeCheckBoxMenuItem( _show_default_node_shapes_external_cbmi, getOptions()
783 .isShowDefaultNodeShapesExternal() );
784 customizeCheckBoxMenuItem( _show_default_node_shapes_internal_cbmi, getOptions()
785 .isShowDefaultNodeShapesInternal() );
786 customizeJMenuItem( _cycle_node_shape_mi );
787 customizeJMenuItem( _cycle_node_fill_mi );
788 customizeJMenuItem( _choose_node_size_mi );
789 customizeCheckBoxMenuItem( _color_labels_same_as_parent_branch, getOptions().isColorLabelsSameAsParentBranch() );
790 customizeCheckBoxMenuItem( _search_case_senstive_cbmi, getOptions().isSearchCaseSensitive() );
791 customizeCheckBoxMenuItem( _show_scale_cbmi, getOptions().isShowScale() );
792 customizeRadioButtonMenuItem( _non_lined_up_cladograms_rbmi,
793 getOptions().getCladogramType() == CLADOGRAM_TYPE.NON_LINED_UP );
794 customizeRadioButtonMenuItem( _uniform_cladograms_rbmi,
795 getOptions().getCladogramType() == CLADOGRAM_TYPE.TOTAL_NODE_SUM_DEP );
796 customizeRadioButtonMenuItem( _ext_node_dependent_cladogram_rbmi,
797 getOptions().getCladogramType() == CLADOGRAM_TYPE.EXT_NODE_SUM_DEP );
798 customizeCheckBoxMenuItem( _show_branch_length_values_cbmi, getOptions().isShowBranchLengthValues() );
799 customizeCheckBoxMenuItem( _show_overview_cbmi, getOptions().isShowOverview() );
800 customizeCheckBoxMenuItem( _search_whole_words_only_cbmi, getOptions().isMatchWholeTermsOnly() );
801 customizeCheckBoxMenuItem( _inverse_search_result_cbmi, getOptions().isInverseSearchResult() );
802 customizeCheckBoxMenuItem( _show_confidence_stddev_cbmi, getOptions().isShowConfidenceStddev() );
803 _jmenubar.add( _options_jmenu );
806 void buildToolsMenu() {
807 _tools_menu = MainFrame.createMenu( "Tools", getConfiguration() );
808 _tools_menu.add( _confcolor_item = new JMenuItem( "Colorize Branches Depending on Confidence" ) );
809 customizeJMenuItem( _confcolor_item );
810 _tools_menu.add( _taxcolor_item = new JMenuItem( "Taxonomy Colorize Branches" ) );
811 customizeJMenuItem( _taxcolor_item );
812 _tools_menu.addSeparator();
813 _tools_menu.add( _remove_visual_styles_item = new JMenuItem( "Delete All Visual Styles From Nodes" ) );
814 _remove_visual_styles_item
815 .setToolTipText( "To remove all node visual styles (fonts, colors) from the current phylogeny." );
816 customizeJMenuItem( _remove_visual_styles_item );
817 _tools_menu.add( _remove_branch_color_item = new JMenuItem( "Delete All Colors From Branches" ) );
818 _remove_branch_color_item.setToolTipText( "To remove all branch color values from the current phylogeny." );
819 customizeJMenuItem( _remove_branch_color_item );
820 _tools_menu.addSeparator();
821 _tools_menu.add( _midpoint_root_item = new JMenuItem( "Midpoint-Root" ) );
822 customizeJMenuItem( _midpoint_root_item );
823 _tools_menu.addSeparator();
824 _tools_menu.add( _collapse_species_specific_subtrees = new JMenuItem( "Collapse Species-Specific Subtrees" ) );
825 customizeJMenuItem( _collapse_species_specific_subtrees );
826 _jmenubar.add( _tools_menu );
829 void buildTypeMenu() {
830 _type_menu = MainFrame.createMenu( MainFrame.TYPE_MENU_HEADER, getConfiguration() );
831 _type_menu.add( _rectangular_type_cbmi = new JCheckBoxMenuItem( MainFrame.RECTANGULAR_TYPE_CBMI_LABEL ) );
832 _type_menu.add( _euro_type_cbmi = new JCheckBoxMenuItem( MainFrame.EURO_TYPE_CBMI_LABEL ) );
833 _type_menu.add( _rounded_type_cbmi = new JCheckBoxMenuItem( MainFrame.ROUNDED_TYPE_CBMI_LABEL ) );
834 _type_menu.add( _curved_type_cbmi = new JCheckBoxMenuItem( MainFrame.CURVED_TYPE_CBMI_LABEL ) );
835 _type_menu.add( _triangular_type_cbmi = new JCheckBoxMenuItem( MainFrame.TRIANGULAR_TYPE_CBMI_LABEL ) );
836 _type_menu.add( _convex_type_cbmi = new JCheckBoxMenuItem( MainFrame.CONVEX_TYPE_CBMI_LABEL ) );
837 _type_menu.add( _unrooted_type_cbmi = new JCheckBoxMenuItem( MainFrame.UNROOTED_TYPE_CBMI_LABEL ) );
838 _type_menu.add( _circular_type_cbmi = new JCheckBoxMenuItem( MainFrame.CIRCULAR_TYPE_CBMI_LABEL ) );
839 customizeCheckBoxMenuItem( _rectangular_type_cbmi, false );
840 customizeCheckBoxMenuItem( _triangular_type_cbmi, false );
841 customizeCheckBoxMenuItem( _euro_type_cbmi, false );
842 customizeCheckBoxMenuItem( _rounded_type_cbmi, false );
843 customizeCheckBoxMenuItem( _curved_type_cbmi, false );
844 customizeCheckBoxMenuItem( _convex_type_cbmi, false );
845 customizeCheckBoxMenuItem( _unrooted_type_cbmi, false );
846 customizeCheckBoxMenuItem( _circular_type_cbmi, false );
847 _unrooted_type_cbmi.setToolTipText( MainFrame.USE_MOUSEWHEEL_SHIFT_TO_ROTATE );
848 _circular_type_cbmi.setToolTipText( MainFrame.USE_MOUSEWHEEL_SHIFT_TO_ROTATE );
849 initializeTypeMenu( getOptions() );
850 _jmenubar.add( _type_menu );
853 void buildViewMenu() {
854 _view_jmenu = MainFrame.createMenu( "View", getConfiguration() );
856 .add( _display_basic_information_item = new JMenuItem( MainFrame.SHOW_BASIC_TREE_INFORMATION_LABEL ) );
857 _view_jmenu.addSeparator();
858 _view_jmenu.add( _view_as_XML_item = new JMenuItem( "as phyloXML" ) );
859 _view_jmenu.add( _view_as_NH_item = new JMenuItem( "as Newick" ) );
860 _view_jmenu.add( _view_as_nexus_item = new JMenuItem( "as Nexus" ) );
861 customizeJMenuItem( _display_basic_information_item );
862 customizeJMenuItem( _view_as_NH_item );
863 customizeJMenuItem( _view_as_XML_item );
864 customizeJMenuItem( _view_as_nexus_item );
865 _jmenubar.add( _view_jmenu );
868 void checkTextFrames() {
869 if ( _textframes.size() > 5 ) {
871 if ( _textframes.getFirst() != null ) {
872 _textframes.getFirst().removeMe();
875 _textframes.removeFirst();
878 catch ( final NoSuchElementException e ) {
884 void clearCurrentExternalNodesDataBuffer() {
885 getCurrentTreePanel().clearCurrentExternalNodesDataBuffer();
888 void customizeCheckBoxMenuItem( final JCheckBoxMenuItem item, final boolean is_selected ) {
889 if ( item != null ) {
890 item.setFont( MainFrame.menu_font );
891 if ( !getConfiguration().isUseNativeUI() ) {
892 item.setBackground( getConfiguration().getGuiMenuBackgroundColor() );
893 item.setForeground( getConfiguration().getGuiMenuTextColor() );
895 item.setSelected( is_selected );
896 item.addActionListener( this );
900 void customizeJMenuItem( final JMenuItem jmi ) {
901 jmi.setFont( MainFrame.menu_font );
902 if ( !getConfiguration().isUseNativeUI() ) {
903 jmi.setBackground( getConfiguration().getGuiMenuBackgroundColor() );
904 jmi.setForeground( getConfiguration().getGuiMenuTextColor() );
906 jmi.addActionListener( this );
909 void displayBasicInformation() {
910 if ( ( getMainPanel().getCurrentPhylogeny() != null ) && !getMainPanel().getCurrentPhylogeny().isEmpty() ) {
911 String title = "Basic Information";
912 if ( !ForesterUtil.isEmpty( getMainPanel().getCurrentPhylogeny().getName() ) ) {
913 title = title + " for \"" + _mainpanel.getCurrentPhylogeny().getName() + "\"";
915 showTextFrame( AptxUtil.createBasicInformation( getMainPanel().getCurrentPhylogeny(), null ), title );
920 if ( !isOKforSDI( false, true ) ) {
923 if ( !_mainpanel.getCurrentPhylogeny().isRooted() ) {
924 JOptionPane.showMessageDialog( this,
925 "Gene tree is not rooted.",
926 "Cannot execute GSDI",
927 JOptionPane.ERROR_MESSAGE );
930 final Phylogeny gene_tree = _mainpanel.getCurrentPhylogeny().copy();
931 gene_tree.setAllNodesToNotCollapse();
932 gene_tree.recalculateNumberOfExternalDescendants( false );
934 final Phylogeny species_tree = _species_tree.copy();
936 gsdi = new GSDI( gene_tree, species_tree, false, true, true, true );
938 catch ( final SDIException e ) {
939 JOptionPane.showMessageDialog( this,
940 e.getLocalizedMessage(),
942 JOptionPane.ERROR_MESSAGE );
945 catch ( final Exception e ) {
946 AptxUtil.unexpectedException( e );
949 gene_tree.setRerootable( false );
950 gene_tree.clearHashIdToNodeMap();
951 gene_tree.recalculateNumberOfExternalDescendants( true );
952 _mainpanel.addPhylogenyInNewTab( gene_tree, getConfiguration(), "gene tree", null );
953 getMainPanel().getControlPanel().setShowEvents( true );
955 final int selected = _mainpanel.getTabbedPane().getSelectedIndex();
956 _mainpanel.addPhylogenyInNewTab( species_tree, getConfiguration(), "species tree", null );
958 _mainpanel.getTabbedPane().setSelectedIndex( selected );
960 _mainpanel.getCurrentTreePanel().setEdited( true );
961 final int poly = PhylogenyMethods.countNumberOfPolytomies( species_tree );
962 if ( gsdi.getStrippedExternalGeneTreeNodes().size() > 0 ) {
963 JOptionPane.showMessageDialog( this,
964 "Duplications: " + gsdi.getDuplicationsSum() + "\n"
965 + "Potential duplications: "
966 + gsdi.getSpeciationOrDuplicationEventsSum() + "\n"
967 + "Speciations: " + gsdi.getSpeciationsSum() + "\n"
968 + "Stripped gene tree nodes: "
969 + gsdi.getStrippedExternalGeneTreeNodes().size() + "\n"
970 + "Taxonomy linkage based on: " + gsdi.getTaxCompBase() + "\n"
971 + "Number of polytomies in species tree used: " + poly + "\n",
972 "GSDI successfully completed",
973 JOptionPane.WARNING_MESSAGE );
976 JOptionPane.showMessageDialog( this,
977 "Duplications: " + gsdi.getDuplicationsSum() + "\n"
978 + "Potential duplications: "
979 + gsdi.getSpeciationOrDuplicationEventsSum() + "\n"
980 + "Speciations: " + gsdi.getSpeciationsSum() + "\n"
981 + "Stripped gene tree nodes: "
982 + gsdi.getStrippedExternalGeneTreeNodes().size() + "\n"
983 + "Taxonomy linkage based on: " + gsdi.getTaxCompBase() + "\n"
984 + "Number of polytomies in species tree used: " + poly + "\n",
985 "GSDI successfully completed",
986 JOptionPane.INFORMATION_MESSAGE );
990 void executeGSDIR() {
991 if ( !isOKforSDI( false, false ) ) {
994 final int p = PhylogenyMethods.countNumberOfPolytomies( _mainpanel.getCurrentPhylogeny() );
996 && !( ( p == 1 ) && ( _mainpanel.getCurrentPhylogeny().getRoot().getNumberOfDescendants() == 3 ) ) ) {
997 JOptionPane.showMessageDialog( this,
998 "Gene tree is not completely binary",
999 "Cannot execute GSDI",
1000 JOptionPane.ERROR_MESSAGE );
1003 final Phylogeny gene_tree = _mainpanel.getCurrentPhylogeny().copy();
1004 gene_tree.setAllNodesToNotCollapse();
1005 gene_tree.recalculateNumberOfExternalDescendants( false );
1007 final Phylogeny species_tree = _species_tree.copy();
1009 gsdir = new GSDIR( gene_tree, species_tree, true, true, true );
1011 catch ( final SDIException e ) {
1012 JOptionPane.showMessageDialog( this,
1013 e.getLocalizedMessage(),
1014 "Error during GSDIR",
1015 JOptionPane.ERROR_MESSAGE );
1018 catch ( final Exception e ) {
1019 AptxUtil.unexpectedException( e );
1022 final Phylogeny result_gene_tree = gsdir.getMinDuplicationsSumGeneTree();
1023 result_gene_tree.setRerootable( false );
1024 result_gene_tree.clearHashIdToNodeMap();
1025 result_gene_tree.recalculateNumberOfExternalDescendants( true );
1026 PhylogenyMethods.orderAppearance( result_gene_tree.getRoot(), true, true, DESCENDANT_SORT_PRIORITY.NODE_NAME );
1027 _mainpanel.addPhylogenyInNewTab( result_gene_tree, getConfiguration(), "gene tree", null );
1028 getMainPanel().getControlPanel().setShowEvents( true );
1030 final int selected = _mainpanel.getTabbedPane().getSelectedIndex();
1031 _mainpanel.addPhylogenyInNewTab( species_tree, getConfiguration(), "species tree", null );
1033 _mainpanel.getTabbedPane().setSelectedIndex( selected );
1035 _mainpanel.getCurrentTreePanel().setEdited( true );
1036 final int poly = PhylogenyMethods.countNumberOfPolytomies( species_tree );
1037 if ( gsdir.getStrippedExternalGeneTreeNodes().size() > 0 ) {
1038 JOptionPane.showMessageDialog( this,
1039 "Minimal duplications: " + gsdir.getMinDuplicationsSum() + "\n"
1040 + "Speciations: " + gsdir.getSpeciationsSum() + "\n"
1041 + "Stripped gene tree nodes: "
1042 + gsdir.getStrippedExternalGeneTreeNodes().size() + "\n"
1043 + "Taxonomy linkage based on: " + gsdir.getTaxCompBase() + "\n"
1044 + "Number of polytomies in species tree used: " + poly + "\n",
1045 "GSDIR successfully completed",
1046 JOptionPane.WARNING_MESSAGE );
1049 JOptionPane.showMessageDialog( this,
1050 "Minimal duplications: " + gsdir.getMinDuplicationsSum() + "\n"
1051 + "Speciations: " + gsdir.getSpeciationsSum() + "\n"
1052 + "Stripped gene tree nodes: "
1053 + gsdir.getStrippedExternalGeneTreeNodes().size() + "\n"
1054 + "Taxonomy linkage based on: " + gsdir.getTaxCompBase() + "\n"
1055 + "Number of polytomies in species tree used: " + poly + "\n",
1056 "GSDIR successfully completed",
1057 JOptionPane.INFORMATION_MESSAGE );
1061 Configuration getConfiguration() {
1062 return _configuration;
1065 TreePanel getCurrentTreePanel() {
1066 return getMainPanel().getCurrentTreePanel();
1069 JCheckBoxMenuItem getlabelDirectionCbmi() {
1070 return _label_direction_cbmi;
1073 Options getOtions() {
1078 final StringBuilder sb = new StringBuilder();
1079 sb.append( "Display options\n" );
1080 sb.append( "-------------------\n" );
1081 sb.append( "Use the checkboxes to select types of information to display on the tree.\n\n" );
1082 sb.append( "Clickable tree nodes\n" );
1083 sb.append( "--------------------\n" );
1084 sb.append( "Tree nodes can be clicked, the action is determined by the 'click on node to' menu\n" );
1085 sb.append( "or by right clicking:\n" );
1086 sb.append( "o Display Node Data -- display information for a node\n" );
1087 sb.append( "o Collapse/Uncollapse -- collapse and uncollapse subtree from clicked node\n" );
1088 sb.append( "o Root/Reroot -- change tree root to clicked node\n" );
1089 sb.append( "o Sub/Super Tree -- toggle between subtree from clicked node and whole tree\n" );
1090 sb.append( "o Swap Descendants -- switch descendant on either side of clicked node\n" );
1091 sb.append( "o Colorize Subtree -- color a subtree\n" );
1092 sb.append( "o Open Sequence Web -- launch a web browser to display sequence information\n" );
1093 sb.append( "o Open Taxonomy Web -- launch a web browser to display taxonomy information\n" );
1094 sb.append( "- there may be additional choices depending on this particular setup\n\n" );
1095 sb.append( "Right clicking on a node always displays the information of a node.\n\n" );
1096 sb.append( "Zooming\n" );
1097 sb.append( "---------\n" );
1098 sb.append( "The mouse wheel and the plus and minus keys control zooming.\n" );
1099 sb.append( "Mouse wheel+Ctrl changes the text size.\n" );
1100 sb.append( "Mouse wheel+Shift controls zooming in vertical direction only.\n" );
1101 sb.append( "Use the buttons on the control panel to zoom the tree in and out, horizontally or vertically.\n" );
1102 sb.append( "The entire tree can be fitted into the window by clicking the \"F\" button, or by pressing F, Delete, or Home.\n" );
1103 sb.append( "The up, down, left, and right keys can be used to move the visible part (if zoomed in).\n" );
1104 sb.append( "Up, down, left, and right+Shift can be used to control zooming horizontally and vertically.\n" );
1105 sb.append( "Plus and minus keys+Ctrl change the text size; F+Ctrl, Delete+Ctrl, or Home+Ctrl resets it.\n\n" );
1106 sb.append( "Quick tree manipulation:\n" );
1107 sb.append( "------------------------\n" );
1108 sb.append( "Order Subtrees -- order the tree by branch length\n" );
1109 sb.append( "Uncollapse All -- uncollapse any and all collapsed branches\n\n" );
1110 sb.append( "phyloXML\n" );
1111 sb.append( "-------------------\n" );
1112 sb.append( "Reference: " + Constants.PHYLOXML_REFERENCE + "\n" );
1113 sb.append( "Website: " + Constants.PHYLOXML_WEB_SITE + "\n" );
1114 sb.append( "Version: " + ForesterConstants.PHYLO_XML_VERSION + "\n" );
1116 sb.append( "For more information: http://www.phylosoft.org/archaeopteryx/\n" );
1117 sb.append( "Email: " + Constants.AUTHOR_EMAIL + "\n\n" );
1118 TextFrame.instantiate( sb.toString(), "Help", _textframes );
1121 void initializeTypeMenu( final Options options ) {
1122 setTypeMenuToAllUnselected();
1124 switch ( options.getPhylogenyGraphicsType() ) {
1126 _convex_type_cbmi.setSelected( true );
1129 _curved_type_cbmi.setSelected( true );
1132 _euro_type_cbmi.setSelected( true );
1135 _rounded_type_cbmi.setSelected( true );
1138 _triangular_type_cbmi.setSelected( true );
1141 _unrooted_type_cbmi.setSelected( true );
1144 _circular_type_cbmi.setSelected( true );
1147 _rectangular_type_cbmi.setSelected( true );
1151 catch ( final NullPointerException np ) {
1152 // In all likelihood, this is caused by menu-less display.
1156 boolean isOKforSDI( final boolean species_tree_has_to_binary, final boolean gene_tree_has_to_binary ) {
1157 if ( ( _mainpanel.getCurrentPhylogeny() == null ) || _mainpanel.getCurrentPhylogeny().isEmpty() ) {
1160 else if ( ( _species_tree == null ) || _species_tree.isEmpty() ) {
1161 JOptionPane.showMessageDialog( this,
1162 "No species tree loaded",
1163 "Cannot execute GSDI",
1164 JOptionPane.ERROR_MESSAGE );
1167 else if ( species_tree_has_to_binary && !_species_tree.isCompletelyBinary() ) {
1168 JOptionPane.showMessageDialog( this,
1169 "Species tree is not completely binary",
1170 "Cannot execute GSDI",
1171 JOptionPane.ERROR_MESSAGE );
1174 else if ( gene_tree_has_to_binary && !_mainpanel.getCurrentPhylogeny().isCompletelyBinary() ) {
1175 JOptionPane.showMessageDialog( this,
1176 "Gene tree is not completely binary",
1177 "Cannot execute GSDI",
1178 JOptionPane.ERROR_MESSAGE );
1186 boolean isSubtreeDisplayed() {
1187 if ( getCurrentTreePanel() != null ) {
1188 if ( getCurrentTreePanel().isCurrentTreeIsSubtree() ) {
1190 .showMessageDialog( this,
1191 "This operation can only be performed on a complete tree, not on the currently displayed sub-tree only.",
1192 "Operation can not be exectuted on a sub-tree",
1193 JOptionPane.WARNING_MESSAGE );
1200 void removeAllTextFrames() {
1201 for( final TextFrame tf : _textframes ) {
1206 _textframes.clear();
1209 void setConfiguration( final Configuration configuration ) {
1210 _configuration = configuration;
1213 void setOptions( final Options options ) {
1217 void setSelectedTypeInTypeMenu( final PHYLOGENY_GRAPHICS_TYPE type ) {
1218 setTypeMenuToAllUnselected();
1222 _circular_type_cbmi.setSelected( true );
1225 _convex_type_cbmi.setSelected( true );
1228 _curved_type_cbmi.setSelected( true );
1231 _euro_type_cbmi.setSelected( true );
1234 _rounded_type_cbmi.setSelected( true );
1237 _rectangular_type_cbmi.setSelected( true );
1240 _triangular_type_cbmi.setSelected( true );
1243 _unrooted_type_cbmi.setSelected( true );
1246 throw new IllegalArgumentException( "unknown type: " + type );
1249 catch ( final NullPointerException np ) {
1250 // In all likelihood, this is caused by menu-less display.
1254 void setTypeMenuToAllUnselected() {
1255 if ( _convex_type_cbmi != null ) {
1256 _convex_type_cbmi.setSelected( false );
1258 if ( _curved_type_cbmi != null ) {
1259 _curved_type_cbmi.setSelected( false );
1261 if ( _euro_type_cbmi != null ) {
1262 _euro_type_cbmi.setSelected( false );
1264 if ( _rounded_type_cbmi != null ) {
1265 _rounded_type_cbmi.setSelected( false );
1267 if ( _triangular_type_cbmi != null ) {
1268 _triangular_type_cbmi.setSelected( false );
1270 if ( _rectangular_type_cbmi != null ) {
1271 _rectangular_type_cbmi.setSelected( false );
1273 if ( _unrooted_type_cbmi != null ) {
1274 _unrooted_type_cbmi.setSelected( false );
1276 if ( _circular_type_cbmi != null ) {
1277 _circular_type_cbmi.setSelected( false );
1282 _mainpanel.getControlPanel().showWhole();
1285 void switchColors() {
1286 final TreeColorSet colorset = getMainPanel().getCurrentTreePanel().getTreeColorSet();
1287 final ColorSchemeChooser csc = new ColorSchemeChooser( getMainPanel(), colorset );
1288 csc.setVisible( true );
1289 getMainPanel().setTreeColorSet( colorset );
1292 void typeChanged( final Object o ) {
1293 updateTypeCheckboxes( getOptions(), o );
1294 updateOptions( getOptions() );
1295 if ( getCurrentTreePanel() != null ) {
1296 final PHYLOGENY_GRAPHICS_TYPE previous_type = getCurrentTreePanel().getPhylogenyGraphicsType();
1297 final PHYLOGENY_GRAPHICS_TYPE new_type = getOptions().getPhylogenyGraphicsType();
1298 if ( ( ( previous_type == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) && ( new_type != PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) )
1299 || ( ( previous_type == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) && ( new_type != PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) )
1300 || ( ( previous_type != PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) && ( new_type == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) )
1301 || ( ( previous_type != PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) && ( new_type == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) ) ) {
1302 getCurrentTreePanel().getControlPanel().showWhole();
1304 if ( getCurrentTreePanel().isPhyHasBranchLengths() && ( new_type != PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) ) {
1305 getCurrentTreePanel().getControlPanel().setDrawPhylogramEnabled( true );
1308 getCurrentTreePanel().getControlPanel().setDrawPhylogramEnabled( false );
1310 getCurrentTreePanel().setPhylogenyGraphicsType( getOptions().getPhylogenyGraphicsType() );
1311 MainFrame.updateScreenTextAntialias( getMainPanel().getTreePanels() );
1315 void updateOptions( final Options options ) {
1316 options.setAntialiasScreen( ( _screen_antialias_cbmi != null ) && _screen_antialias_cbmi.isSelected() );
1317 options.setBackgroundColorGradient( ( _background_gradient_cbmi != null )
1318 && _background_gradient_cbmi.isSelected() );
1319 options.setShowDomainLabels( ( _show_domain_labels != null ) && _show_domain_labels.isSelected() );
1320 options.setShowAnnotationRefSource( ( _show_annotation_ref_source != null )
1321 && _show_annotation_ref_source.isSelected() );
1322 options.setAbbreviateScientificTaxonNames( ( _abbreviate_scientific_names != null )
1323 && _abbreviate_scientific_names.isSelected() );
1324 options.setColorLabelsSameAsParentBranch( ( _color_labels_same_as_parent_branch != null )
1325 && _color_labels_same_as_parent_branch.isSelected() );
1326 options.setShowDefaultNodeShapesInternal( ( _show_default_node_shapes_internal_cbmi != null )
1327 && _show_default_node_shapes_internal_cbmi.isSelected() );
1328 options.setShowDefaultNodeShapesExternal( ( _show_default_node_shapes_external_cbmi != null )
1329 && _show_default_node_shapes_external_cbmi.isSelected() );
1330 if ( ( _non_lined_up_cladograms_rbmi != null ) && ( _non_lined_up_cladograms_rbmi.isSelected() ) ) {
1331 options.setCladogramType( CLADOGRAM_TYPE.NON_LINED_UP );
1333 else if ( ( _uniform_cladograms_rbmi != null ) && ( _uniform_cladograms_rbmi.isSelected() ) ) {
1334 options.setCladogramType( CLADOGRAM_TYPE.TOTAL_NODE_SUM_DEP );
1336 else if ( ( _ext_node_dependent_cladogram_rbmi != null ) && ( _ext_node_dependent_cladogram_rbmi.isSelected() ) ) {
1337 options.setCladogramType( CLADOGRAM_TYPE.EXT_NODE_SUM_DEP );
1339 options.setSearchCaseSensitive( ( _search_case_senstive_cbmi != null )
1340 && _search_case_senstive_cbmi.isSelected() );
1341 if ( ( _show_scale_cbmi != null ) && _show_scale_cbmi.isEnabled() ) {
1342 options.setShowScale( _show_scale_cbmi.isSelected() );
1344 if ( _label_direction_cbmi != null ) {
1345 if ( _label_direction_cbmi.isSelected() ) {
1346 options.setNodeLabelDirection( NODE_LABEL_DIRECTION.RADIAL );
1349 options.setNodeLabelDirection( NODE_LABEL_DIRECTION.HORIZONTAL );
1352 options.setShowOverview( ( _show_overview_cbmi != null ) && _show_overview_cbmi.isSelected() );
1353 options.setShowConfidenceStddev( ( _show_confidence_stddev_cbmi != null )
1354 && _show_confidence_stddev_cbmi.isSelected() );
1355 if ( ( _show_branch_length_values_cbmi != null ) && _show_branch_length_values_cbmi.isEnabled() ) {
1356 options.setShowBranchLengthValues( _show_branch_length_values_cbmi.isSelected() );
1358 options.setMatchWholeTermsOnly( ( _search_whole_words_only_cbmi != null )
1359 && _search_whole_words_only_cbmi.isSelected() );
1360 options.setInverseSearchResult( ( _inverse_search_result_cbmi != null )
1361 && _inverse_search_result_cbmi.isSelected() );
1362 if ( ( _rectangular_type_cbmi != null ) && _rectangular_type_cbmi.isSelected() ) {
1363 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR );
1365 else if ( ( _triangular_type_cbmi != null ) && _triangular_type_cbmi.isSelected() ) {
1366 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.TRIANGULAR );
1368 else if ( ( _curved_type_cbmi != null ) && _curved_type_cbmi.isSelected() ) {
1369 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CURVED );
1371 else if ( ( _convex_type_cbmi != null ) && _convex_type_cbmi.isSelected() ) {
1372 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CONVEX );
1374 else if ( ( _euro_type_cbmi != null ) && _euro_type_cbmi.isSelected() ) {
1375 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE );
1377 else if ( ( _rounded_type_cbmi != null ) && _rounded_type_cbmi.isSelected() ) {
1378 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.ROUNDED );
1380 else if ( ( _unrooted_type_cbmi != null ) && _unrooted_type_cbmi.isSelected() ) {
1381 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.UNROOTED );
1383 else if ( ( _circular_type_cbmi != null ) && _circular_type_cbmi.isSelected() ) {
1384 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CIRCULAR );
1386 if ( ( _color_by_taxonomic_group_cbmi != null ) && _color_by_taxonomic_group_cbmi.isEnabled() ) {
1387 options.setColorByTaxonomicGroup( _color_by_taxonomic_group_cbmi.isSelected() );
1391 void updateTypeCheckboxes( final Options options, final Object o ) {
1392 setTypeMenuToAllUnselected();
1393 ( ( JCheckBoxMenuItem ) o ).setSelected( true );
1396 void viewAsNexus() {
1397 if ( ( getMainPanel().getCurrentPhylogeny() != null ) && !getMainPanel().getCurrentPhylogeny().isEmpty() ) {
1398 String title = "Nexus";
1399 if ( !ForesterUtil.isEmpty( getMainPanel().getCurrentPhylogeny().getName() ) ) {
1400 title = "\"" + getMainPanel().getCurrentPhylogeny().getName() + "\" in " + title;
1402 showTextFrame( getMainPanel().getCurrentPhylogeny().toNexus( getOptions()
1403 .getNhConversionSupportValueStyle() ),
1409 if ( ( getMainPanel().getCurrentPhylogeny() != null ) && !getMainPanel().getCurrentPhylogeny().isEmpty() ) {
1410 String title = "New Hampshire";
1411 if ( !ForesterUtil.isEmpty( getMainPanel().getCurrentPhylogeny().getName() ) ) {
1412 title = "\"" + getMainPanel().getCurrentPhylogeny().getName() + "\" in " + title;
1414 showTextFrame( getMainPanel().getCurrentPhylogeny().toNewHampshire( getOptions()
1415 .getNhConversionSupportValueStyle() ),
1421 if ( ( getMainPanel().getCurrentPhylogeny() != null ) && !getMainPanel().getCurrentPhylogeny().isEmpty() ) {
1422 String title = "phyloXML";
1423 if ( !ForesterUtil.isEmpty( getMainPanel().getCurrentPhylogeny().getName() ) ) {
1424 title = "\"" + getMainPanel().getCurrentPhylogeny().getName() + "\" in " + title;
1426 showTextFrame( getMainPanel().getCurrentPhylogeny().toPhyloXML( 0 ), title );
1430 private void chooseFont() {
1431 final FontChooser fc = new FontChooser();
1432 fc.setFont( getMainPanel().getTreeFontSet().getLargeFont() );
1433 fc.showDialog( this, "Select the Base Font" );
1434 getMainPanel().getTreeFontSet().setBaseFont( fc.getFont() );
1437 private void chooseMinimalConfidence() {
1438 final String s = ( String ) JOptionPane
1439 .showInputDialog( this,
1440 "Please the minimum for confidence values to be displayed.\n" + "[current value: "
1441 + getOptions().getMinConfidenceValue() + "]\n",
1442 "Minimal Confidence Value",
1443 JOptionPane.QUESTION_MESSAGE,
1446 getOptions().getMinConfidenceValue() );
1447 if ( !ForesterUtil.isEmpty( s ) ) {
1448 boolean success = true;
1450 final String m_str = s.trim();
1451 if ( !ForesterUtil.isEmpty( m_str ) ) {
1453 m = Double.parseDouble( m_str );
1455 catch ( final Exception ex ) {
1462 if ( success && ( m >= 0.0 ) ) {
1463 getOptions().setMinConfidenceValue( m );
1468 private void customizeRadioButtonMenuItem( final JRadioButtonMenuItem item, final boolean is_selected ) {
1469 if ( item != null ) {
1470 item.setFont( MainFrame.menu_font );
1471 if ( !getConfiguration().isUseNativeUI() ) {
1472 item.setBackground( getConfiguration().getGuiMenuBackgroundColor() );
1473 item.setForeground( getConfiguration().getGuiMenuTextColor() );
1475 item.setSelected( is_selected );
1476 item.addActionListener( this );
1480 private MainPanel getMainPanel() {
1484 private Phylogeny getSpeciesTree() {
1485 return _species_tree;
1488 private boolean isScreenAntialias() {
1492 private void removeBranchColors() {
1493 if ( getMainPanel().getCurrentPhylogeny() != null ) {
1494 AptxUtil.removeBranchColors( getMainPanel().getCurrentPhylogeny() );
1498 private void removeVisualStyles() {
1499 if ( getMainPanel().getCurrentPhylogeny() != null ) {
1500 AptxUtil.removeVisualStyles( getMainPanel().getCurrentPhylogeny() );
1504 private void setMainPanel( final MainPanelApplets main_panel ) {
1505 _mainpanel = main_panel;
1508 private void setSpeciesTree( final Phylogeny species_tree ) {
1509 _species_tree = species_tree;
1512 private void setupUI() {
1514 if ( getConfiguration().isUseNativeUI() ) {
1515 UIManager.setLookAndFeel( UIManager.getSystemLookAndFeelClassName() );
1518 UIManager.setLookAndFeel( UIManager.getCrossPlatformLookAndFeelClassName() );
1521 catch ( final UnsupportedLookAndFeelException e ) {
1522 AptxUtil.dieWithSystemError( "UnsupportedLookAndFeelException: " + e.toString() );
1524 catch ( final ClassNotFoundException e ) {
1525 AptxUtil.dieWithSystemError( "ClassNotFoundException: " + e.toString() );
1527 catch ( final InstantiationException e ) {
1528 AptxUtil.dieWithSystemError( "InstantiationException: " + e.toString() );
1530 catch ( final IllegalAccessException e ) {
1531 AptxUtil.dieWithSystemError( "IllegalAccessException: " + e.toString() );
1533 catch ( final Exception e ) {
1534 AptxUtil.dieWithSystemError( e.toString() );
1538 static void setupScreenTextAntialias( final List<TreePanel> treepanels, final boolean antialias ) {
1539 for( final TreePanel tree_panel : treepanels ) {
1540 tree_panel.setTextAntialias();