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 JCheckBoxMenuItem _show_domain_labels;
100 private JCheckBoxMenuItem _show_annotation_ref_source;
101 private JCheckBoxMenuItem _color_labels_same_as_parent_branch;
102 private JCheckBoxMenuItem _abbreviate_scientific_names;
103 private JCheckBoxMenuItem _screen_antialias_cbmi;
104 private JCheckBoxMenuItem _background_gradient_cbmi;
105 private JCheckBoxMenuItem _color_by_taxonomic_group_cbmi;
106 private JRadioButtonMenuItem _non_lined_up_cladograms_rbmi;
107 private JRadioButtonMenuItem _uniform_cladograms_rbmi;
108 private JRadioButtonMenuItem _ext_node_dependent_cladogram_rbmi;
109 private Options _options;
110 private JMenuItem _choose_font_mi;
111 private JMenuItem _switch_colors_mi;
112 JCheckBoxMenuItem _label_direction_cbmi;
113 private JCheckBoxMenuItem _show_scale_cbmi;
114 private JCheckBoxMenuItem _search_case_senstive_cbmi;
115 private JCheckBoxMenuItem _search_whole_words_only_cbmi;
116 private JCheckBoxMenuItem _inverse_search_result_cbmi;
117 private JCheckBoxMenuItem _show_overview_cbmi;
118 private JMenuItem _choose_minimal_confidence_mi;
119 private JCheckBoxMenuItem _show_branch_length_values_cbmi;
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 JMenuItem _cycle_node_shape_mi;
126 private JMenuItem _cycle_node_fill_mi;
127 private JMenuItem _choose_node_size_mi;
128 private JCheckBoxMenuItem _taxonomy_colorize_node_shapes_cbmi;
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 == _switch_colors_mi ) {
171 else if ( o == _display_basic_information_item ) {
172 displayBasicInformation();
174 else if ( o == _view_as_NH_item ) {
177 else if ( o == _view_as_XML_item ) {
180 else if ( o == _view_as_nexus_item ) {
183 else if ( o == _super_tiny_fonts_mi ) {
184 if ( getCurrentTreePanel() != null ) {
185 getCurrentTreePanel().setSuperTinyFonts();
186 getCurrentTreePanel().repaint();
189 else if ( o == _tiny_fonts_mi ) {
190 if ( getCurrentTreePanel() != null ) {
191 getCurrentTreePanel().setTinyFonts();
192 getCurrentTreePanel().repaint();
195 else if ( o == _small_fonts_mi ) {
196 if ( getCurrentTreePanel() != null ) {
197 getCurrentTreePanel().setSmallFonts();
198 getCurrentTreePanel().repaint();
201 else if ( o == _medium_fonts_mi ) {
202 if ( getCurrentTreePanel() != null ) {
203 getCurrentTreePanel().setMediumFonts();
204 getCurrentTreePanel().repaint();
207 else if ( o == _large_fonts_mi ) {
208 if ( getCurrentTreePanel() != null ) {
209 getCurrentTreePanel().setLargeFonts();
210 getCurrentTreePanel().repaint();
213 else if ( o == _choose_font_mi ) {
216 else if ( o == _choose_minimal_confidence_mi ) {
217 chooseMinimalConfidence();
219 else if ( o == _choose_node_size_mi ) {
220 MainFrame.chooseNodeSize( getOptions(), this );
222 else if ( o == _overview_placment_mi ) {
223 MainFrame.cycleOverview( getOptions(), getCurrentTreePanel() );
225 else if ( o == _cycle_node_fill_mi ) {
226 MainFrame.cycleNodeFill( getOptions(), getCurrentTreePanel() );
228 else if ( o == _cycle_node_shape_mi ) {
229 MainFrame.cycleNodeShape( getOptions(), getCurrentTreePanel() );
231 else if ( o == _non_lined_up_cladograms_rbmi ) {
232 updateOptions( getOptions() );
233 _mainpanel.getControlPanel().showWhole();
235 else if ( o == _uniform_cladograms_rbmi ) {
236 updateOptions( getOptions() );
237 _mainpanel.getControlPanel().showWhole();
239 else if ( o == _ext_node_dependent_cladogram_rbmi ) {
240 updateOptions( getOptions() );
241 _mainpanel.getControlPanel().showWhole();
243 else if ( o == _search_case_senstive_cbmi ) {
244 updateOptions( getOptions() );
245 getMainPanel().getControlPanel().search();
247 else if ( o == _search_whole_words_only_cbmi ) {
248 updateOptions( getOptions() );
249 getMainPanel().getControlPanel().search();
251 else if ( o == _inverse_search_result_cbmi ) {
252 updateOptions( getOptions() );
253 getMainPanel().getControlPanel().search();
255 else if ( o == _show_scale_cbmi ) {
256 updateOptions( getOptions() );
258 else if ( o == _show_branch_length_values_cbmi ) {
259 updateOptions( getOptions() );
261 else if ( o == _show_confidence_stddev_cbmi ) {
262 updateOptions( getOptions() );
264 else if ( o == _label_direction_cbmi ) {
265 updateOptions( getOptions() );
267 else if ( o == _abbreviate_scientific_names ) {
268 updateOptions( getOptions() );
270 else if ( o == _show_overview_cbmi ) {
271 updateOptions( getOptions() );
272 if ( getCurrentTreePanel() != null ) {
273 getCurrentTreePanel().updateOvSizes();
276 else if ( ( o == _rectangular_type_cbmi ) || ( o == _triangular_type_cbmi ) || ( o == _curved_type_cbmi )
277 || ( o == _convex_type_cbmi ) || ( o == _rounded_type_cbmi ) || ( o == _euro_type_cbmi )
278 || ( o == _unrooted_type_cbmi ) || ( o == _circular_type_cbmi ) ) {
281 else if ( o == _screen_antialias_cbmi ) {
282 updateOptions( getOptions() );
283 setupScreenTextAntialias( getMainPanel().getTreePanels(), isScreenAntialias() );
285 else if ( o == _background_gradient_cbmi ) {
286 updateOptions( getOptions() );
288 else if ( o == _show_domain_labels ) {
289 updateOptions( getOptions() );
291 else if ( o == _color_labels_same_as_parent_branch ) {
292 updateOptions( getOptions() );
294 else if ( o == _show_default_node_shapes_internal_cbmi ) {
295 updateOptions( getOptions() );
297 else if ( o == _show_default_node_shapes_external_cbmi ) {
298 updateOptions( getOptions() );
300 else if ( o == _taxonomy_colorize_node_shapes_cbmi ) {
301 updateOptions( getOptions() );
303 else if ( o == _about_item ) {
306 else if ( o == _help_item ) {
309 else if ( o == _website_item ) {
311 AptxUtil.openWebsite( Constants.APTX_WEB_SITE, true, this );
313 catch ( final IOException e1 ) {
314 ForesterUtil.printErrorMessage( Constants.PRG_NAME, e1.toString() );
317 else if ( o == _phyloxml_website_item ) {
319 AptxUtil.openWebsite( Constants.PHYLOXML_WEB_SITE, true, this );
321 catch ( final IOException e1 ) {
322 ForesterUtil.printErrorMessage( Constants.PRG_NAME, e1.toString() );
325 else if ( o == _aptx_ref_item ) {
327 AptxUtil.openWebsite( Constants.APTX_REFERENCE_URL, true, this );
329 catch ( final IOException e1 ) {
330 ForesterUtil.printErrorMessage( Constants.PRG_NAME, e1.toString() );
333 else if ( o == _phyloxml_ref_item ) {
335 AptxUtil.openWebsite( Constants.PHYLOXML_REFERENCE_URL, true, this );
337 catch ( final IOException e1 ) {
338 ForesterUtil.printErrorMessage( Constants.PRG_NAME, e1.toString() );
341 else if ( o == _color_by_taxonomic_group_cbmi ) {
342 updateOptions( getOptions() );
348 public void destroy() {
349 AptxUtil.printAppletMessage( NAME, "going to be destroyed " );
350 removeAllTextFrames();
351 if ( getMainPanel() != null ) {
352 getMainPanel().terminate();
357 * This method returns the current external node data which
358 * has been selected by the user by clicking the "Return ..."
359 * menu item. This method is expected to be called from Javascript or
362 * @return current external node data as String
364 public String getCurrentExternalNodesDataBuffer() {
365 return getCurrentTreePanel().getCurrentExternalNodesDataBufferAsString();
368 public int getCurrentExternalNodesDataBufferChangeCounter() {
369 return getCurrentTreePanel().getCurrentExternalNodesDataBufferChangeCounter();
372 public int getCurrentExternalNodesDataBufferLength() {
373 return getCurrentTreePanel().getCurrentExternalNodesDataBufferAsString().length();
377 * This method returns the current phylogeny as a string in the chosen format
379 * @param format must be NH, NHX, NEXUS or PHYLOXML
380 * @return the phylogeny string
381 * @author Herve Menager
383 public String getCurrentPhylogeny( final String format ) {
384 removeAllTextFrames();
385 if ( ( getMainPanel().getCurrentPhylogeny() == null ) || getMainPanel().getCurrentPhylogeny().isEmpty()
386 || ( getMainPanel().getCurrentPhylogeny().getNumberOfExternalNodes() > 10000 ) ) {
389 switch ( ForesterConstants.PhylogeneticTreeFormats.valueOf( format ) ) {
391 return getMainPanel().getCurrentPhylogeny().toNewHampshire();
393 return getMainPanel().getCurrentPhylogeny().toNewHampshireX();
395 return getMainPanel().getCurrentPhylogeny().toNexus();
397 return getMainPanel().getCurrentPhylogeny().toPhyloXML( -1 );
405 * This method returns a view of the current phylogeny in a chosen
406 * graphics format, base64-encoded in a string so that in can be used
409 * @param format must be GraphicsExportType (gif, jpg, pdf, png, tif, bmp)
410 * @return the phylogeny string
411 * @author Herve Menager
413 public String getCurrentPhylogenyGraphicsAsBase64EncodedString( final String format ) {
414 final ByteArrayOutputStream baos = new ByteArrayOutputStream();
416 AptxUtil.writePhylogenyToGraphicsByteArrayOutputStream( baos,
417 _mainpanel.getWidth(),
418 _mainpanel.getHeight(),
419 getCurrentTreePanel(),
420 getCurrentTreePanel().getControlPanel(),
421 GraphicsExportType.valueOf( format ),
424 catch ( final IOException ioe ) {
425 ForesterUtil.printErrorMessage( NAME, ioe.toString() );
426 ioe.printStackTrace();
427 JOptionPane.showMessageDialog( this,
428 NAME + ": Failed to generate graphics: " + "\nException: " + ioe,
429 "Failed to generate graphics",
430 JOptionPane.ERROR_MESSAGE );
433 final byte[] bytes = baos.toByteArray();
434 final String dataImg = Base64.encodeBase64String( bytes );
438 public Options getOptions() {
444 final String config_filename = getParameter( Constants.APPLET_PARAM_NAME_FOR_CONFIG_FILE_URL );
445 AptxUtil.printAppletMessage( NAME, "URL for configuration file is: " + config_filename );
446 final Configuration configuration = new Configuration( config_filename, true, true, true );
447 setConfiguration( configuration );
448 setOptions( Options.createInstance( configuration ) );
451 Phylogeny[] phys = null;
452 final String tree_url_str = getParameter( Constants.APPLET_PARAM_NAME_FOR_URL_OF_TREE_TO_LOAD );
453 AptxUtil.printAppletMessage( NAME, "URL for phylogenies is " + tree_url_str );
454 // Get URL to tree file
455 if ( tree_url_str != null ) {
457 phys_url = new URL( tree_url_str );
459 catch ( final Exception e ) {
460 ForesterUtil.printErrorMessage( NAME, "error: " + e );
462 JOptionPane.showMessageDialog( this, NAME + ": Could not create URL from: \"" + tree_url_str
463 + "\"\nException: " + e, "Failed to create URL", JOptionPane.ERROR_MESSAGE );
466 // Load the tree from URL
467 if ( phys_url != null ) {
469 phys = AptxUtil.readPhylogeniesFromUrl( phys_url,
470 getConfiguration().isValidatePhyloXmlAgainstSchema(),
471 getConfiguration().isReplaceUnderscoresInNhParsing(),
472 getConfiguration().isInternalNumberAreConfidenceForNhParsing(),
473 getConfiguration().getTaxonomyExtraction(),
474 getConfiguration().isMidpointReroot() );
476 catch ( final Exception e ) {
477 ForesterUtil.printErrorMessage( NAME, e.toString() );
479 JOptionPane.showMessageDialog( this,
480 NAME + ": Failed to read phylogenies: " + "\nException: " + e,
481 "Failed to read phylogenies",
482 JOptionPane.ERROR_MESSAGE );
485 if ( ( phys == null ) || ( phys.length < 1 ) ) {
486 ForesterUtil.printErrorMessage( NAME, "phylogenies from [" + phys_url + "] are null or empty" );
487 JOptionPane.showMessageDialog( this,
488 NAME + ": phylogenies from [" + phys_url + "] are null or empty",
489 "Failed to read phylogenies",
490 JOptionPane.ERROR_MESSAGE );
494 AptxUtil.printAppletMessage( NAME, "loaded " + phys.length + " phylogenies from: " + phys_url );
497 final String species_tree_url_str = getParameter( Constants.APPLET_PARAM_NAME_FOR_URL_OF_SPECIES_TREE_TO_LOAD );
498 if ( !ForesterUtil.isEmpty( species_tree_url_str ) ) {
499 AptxUtil.printAppletMessage( NAME, "URL of species tree to load: \"" + species_tree_url_str + "\"" );
500 Phylogeny[] species_trees = null;
502 final URL species_tree_url = new URL( species_tree_url_str );
503 species_trees = AptxUtil.readPhylogeniesFromUrl( species_tree_url,
504 configuration.isValidatePhyloXmlAgainstSchema(),
505 configuration.isReplaceUnderscoresInNhParsing(),
507 TAXONOMY_EXTRACTION.NO,
510 catch ( final IOException e ) {
511 ForesterUtil.printErrorMessage( NAME, "could not read species tree from [" + species_tree_url_str
513 JOptionPane.showMessageDialog( this, NAME + ": could not read species tree from ["
514 + species_tree_url_str + "]", "Failed to read species tree", JOptionPane.ERROR_MESSAGE );
516 if ( ( species_trees != null ) && ( species_trees.length > 0 ) ) {
517 AptxUtil.printAppletMessage( NAME, "successfully read species tree" );
518 if ( species_trees[ 0 ].isEmpty() ) {
519 ForesterUtil.printErrorMessage( NAME, "species tree is empty" );
521 else if ( !species_trees[ 0 ].isRooted() ) {
522 ForesterUtil.printErrorMessage( NAME, "species tree is not rooted" );
525 setSpeciesTree( species_trees[ 0 ] );
526 AptxUtil.printAppletMessage( NAME, "species tree OK" );
532 setMainPanel( new MainPanelApplets( getConfiguration(), this ) );
533 _jmenubar = new JMenuBar();
534 if ( !getConfiguration().isHideControlPanelAndMenubar() ) {
535 if ( !getConfiguration().isUseNativeUI() ) {
536 _jmenubar.setBackground( getConfiguration().getGuiMenuBackgroundColor() );
538 if ( getSpeciesTree() != null ) {
547 setJMenuBar( _jmenubar );
549 final Container contentpane = getContentPane();
550 contentpane.setLayout( new BorderLayout() );
551 contentpane.add( getMainPanel(), BorderLayout.CENTER );
552 addComponentListener( new ComponentAdapter() {
555 public void componentResized( final ComponentEvent e ) {
556 if ( getMainPanel().getCurrentTreePanel() != null ) {
557 getMainPanel().getCurrentTreePanel().calcParametersForPainting( getMainPanel()
558 .getCurrentTreePanel()
561 .getCurrentTreePanel()
564 .isAllowFontSizeChange() );
568 if ( getConfiguration().isUseTabbedDisplay() ) {
569 AptxUtil.printAppletMessage( NAME, "using tabbed display" );
570 AptxUtil.addPhylogeniesToTabs( phys,
571 new File( phys_url.getFile() ).getName(),
577 AptxUtil.printAppletMessage( NAME, "not using tabbed display" );
578 if ( getSpeciesTree() != null ) {
579 AptxUtil.printAppletMessage( NAME,
580 "Warning: gsdi (gene duplication inference) only available tabbed display" );
582 AptxUtil.addPhylogenyToPanel( phys, getConfiguration(), getMainPanel() );
586 getMainPanel().getControlPanel().showWholeAll();
587 getMainPanel().getControlPanel().showWhole();
589 AptxUtil.printAppletMessage( NAME, "successfully initialized" );
591 getCurrentTreePanel().getControlPanel().getSequenceRelationTypeBox().removeAllItems();
592 for( final SequenceRelation.SEQUENCE_RELATION_TYPE type : getMainPanel().getCurrentPhylogeny()
593 .getRelevantSequenceRelationTypes() ) {
594 getCurrentTreePanel().getControlPanel().getSequenceRelationTypeBox().addItem( type );
596 final String default_relation = getParameter( Constants.APPLET_PARAM_NAME_FOR_DEFAULT_SEQUENCE_RELATION_TYPE );
597 if ( default_relation != null ) {
598 getCurrentTreePanel().getControlPanel().getSequenceRelationTypeBox().setSelectedItem( default_relation );
600 final String default_sequence = getParameter( Constants.APPLET_PARAM_NAME_FOR_DEFAULT_QUERY_SEQUENCE );
601 if ( default_sequence != null ) {
602 getCurrentTreePanel().getControlPanel().getSequenceRelationBox().setSelectedItem( default_sequence );
608 public void showTextFrame( final String s, final String title ) {
610 _textframes.addLast( TextFrame.instantiate( s, title, _textframes ) );
614 public void start() {
615 if ( getMainPanel() != null ) {
616 getMainPanel().validate();
619 requestFocusInWindow();
621 AptxUtil.printAppletMessage( NAME, "started" );
624 void buildAnalysisMenu() {
625 _analysis_menu = MainFrame.createMenu( "Analysis", getConfiguration() );
626 _analysis_menu.add( _gsdi_item = new JMenuItem( "GSDI (Generalized Speciation Duplication Inference)" ) );
627 _analysis_menu.add( _gsdir_item = new JMenuItem( "GSDIR (GSDI with re-rooting)" ) );
628 customizeJMenuItem( _gsdi_item );
629 customizeJMenuItem( _gsdir_item );
630 // _analysis_menu.addSeparator();
631 // _analysis_menu.add( _lineage_inference = new JMenuItem( INFER_ANCESTOR_TAXONOMIES ) );
632 // customizeJMenuItem( _lineage_inference );
633 // _lineage_inference.setToolTipText( "Inference of ancestor taxonomies/lineages" );
634 _jmenubar.add( _analysis_menu );
637 void buildFontSizeMenu() {
638 _font_size_menu = MainFrame.createMenu( MainFrame.FONT_SIZE_MENU_LABEL, getConfiguration() );
639 _font_size_menu.add( _super_tiny_fonts_mi = new JMenuItem( "Super tiny fonts" ) );
640 _font_size_menu.add( _tiny_fonts_mi = new JMenuItem( "Tiny fonts" ) );
641 _font_size_menu.add( _small_fonts_mi = new JMenuItem( "Small fonts" ) );
642 _font_size_menu.add( _medium_fonts_mi = new JMenuItem( "Medium fonts" ) );
643 _font_size_menu.add( _large_fonts_mi = new JMenuItem( "Large fonts" ) );
644 customizeJMenuItem( _super_tiny_fonts_mi );
645 customizeJMenuItem( _tiny_fonts_mi );
646 customizeJMenuItem( _small_fonts_mi );
647 customizeJMenuItem( _medium_fonts_mi );
648 customizeJMenuItem( _large_fonts_mi );
649 _jmenubar.add( _font_size_menu );
652 void buildHelpMenu() {
653 _help_jmenu = MainFrame.createMenu( "Help", getConfiguration() );
654 _help_jmenu.add( _help_item = new JMenuItem( "Help" ) );
655 _help_jmenu.add( _website_item = new JMenuItem( "Archaeopteryx Home" ) );
656 _aptx_ref_item = new JMenuItem( "Archaeopteryx Reference" );
657 _help_jmenu.add( _phyloxml_website_item = new JMenuItem( "phyloXML Home" ) );
658 _help_jmenu.add( _phyloxml_ref_item = new JMenuItem( "phyloXML Reference" ) );
659 _help_jmenu.addSeparator();
660 _help_jmenu.add( _about_item = new JMenuItem( "About" ) );
661 customizeJMenuItem( _help_item );
662 customizeJMenuItem( _website_item );
663 customizeJMenuItem( _phyloxml_website_item );
664 customizeJMenuItem( _aptx_ref_item );
665 customizeJMenuItem( _phyloxml_ref_item );
666 customizeJMenuItem( _about_item );
667 _phyloxml_ref_item.setToolTipText( MainFrame.PHYLOXML_REF_TOOL_TIP );
668 _aptx_ref_item.setToolTipText( MainFrame.APTX_REF_TOOL_TIP );
669 _jmenubar.add( _help_jmenu );
672 void buildOptionsMenu() {
673 _options_jmenu = MainFrame.createMenu( MainFrame.OPTIONS_HEADER, getConfiguration() );
674 _options_jmenu.addChangeListener( new ChangeListener() {
677 public void stateChanged( final ChangeEvent e ) {
678 MainFrame.setOvPlacementColorChooseMenuItem( _overview_placment_mi, getOptions() );
679 MainFrame.setTextColorChooseMenuItem( _switch_colors_mi, getCurrentTreePanel() );
681 .setTextMinSupportMenuItem( _choose_minimal_confidence_mi, getOptions(), getCurrentTreePanel() );
682 MainFrame.setTextForFontChooserMenuItem( _choose_font_mi, MainFrame
683 .createCurrentFontDesc( getMainPanel().getTreeFontSet() ) );
684 MainFrame.updateOptionsMenuDependingOnPhylogenyType( getMainPanel(),
686 _show_branch_length_values_cbmi,
687 _non_lined_up_cladograms_rbmi,
688 _uniform_cladograms_rbmi,
689 _ext_node_dependent_cladogram_rbmi,
690 _label_direction_cbmi );
691 MainFrame.setCycleNodeFillMenuItem( _cycle_node_fill_mi, getOptions() );
692 MainFrame.setCycleNodeShapeMenuItem( _cycle_node_shape_mi, getOptions() );
693 MainFrame.setTextNodeSizeMenuItem( _choose_node_size_mi, getOptions() );
696 _options_jmenu.add( MainFrame.customizeMenuItemAsLabel( new JMenuItem( MainFrame.DISPLAY_SUBHEADER ),
697 getConfiguration() ) );
699 .add( _ext_node_dependent_cladogram_rbmi = new JRadioButtonMenuItem( MainFrame.NONUNIFORM_CLADOGRAMS_LABEL ) );
700 _options_jmenu.add( _uniform_cladograms_rbmi = new JRadioButtonMenuItem( MainFrame.UNIFORM_CLADOGRAMS_LABEL ) );
702 .add( _non_lined_up_cladograms_rbmi = new JRadioButtonMenuItem( MainFrame.NON_LINED_UP_CLADOGRAMS_LABEL ) );
703 _radio_group_1 = new ButtonGroup();
704 _radio_group_1.add( _ext_node_dependent_cladogram_rbmi );
705 _radio_group_1.add( _uniform_cladograms_rbmi );
706 _radio_group_1.add( _non_lined_up_cladograms_rbmi );
708 _options_jmenu.add( _show_overview_cbmi = new JCheckBoxMenuItem( MainFrame.SHOW_OVERVIEW_LABEL ) );
709 _options_jmenu.add( _show_scale_cbmi = new JCheckBoxMenuItem( MainFrame.DISPLAY_SCALE_LABEL ) );
711 .add( _show_branch_length_values_cbmi = new JCheckBoxMenuItem( MainFrame.DISPLAY_BRANCH_LENGTH_VALUES_LABEL ) );
713 .add( _show_default_node_shapes_internal_cbmi = new JCheckBoxMenuItem( MainFrame.DISPLAY_NODE_BOXES_LABEL_INT ) );
715 .add( _show_default_node_shapes_external_cbmi = new JCheckBoxMenuItem( MainFrame.DISPLAY_NODE_BOXES_LABEL_EXT ) );
716 if ( getConfiguration().doDisplayOption( Configuration.show_domain_architectures ) ) {
717 _options_jmenu.add( _show_domain_labels = new JCheckBoxMenuItem( MainFrame.SHOW_DOMAIN_LABELS_LABEL ) );
719 _options_jmenu.add( _show_annotation_ref_source = new JCheckBoxMenuItem( MainFrame.SHOW_ANN_REF_SOURCE_LABEL ) );
720 _options_jmenu.add( _show_confidence_stddev_cbmi = new JCheckBoxMenuItem( MainFrame.SHOW_CONF_STDDEV_LABEL ) );
722 .add( _color_by_taxonomic_group_cbmi = new JCheckBoxMenuItem( MainFrame.COLOR_BY_TAXONOMIC_GROUP ) );
724 .add( _taxonomy_colorize_node_shapes_cbmi = new JCheckBoxMenuItem( MainFrame.TAXONOMY_COLORIZE_NODE_SHAPES_LABEL ) );
726 .add( _color_labels_same_as_parent_branch = new JCheckBoxMenuItem( MainFrame.COLOR_LABELS_LABEL ) );
727 _color_labels_same_as_parent_branch.setToolTipText( MainFrame.COLOR_LABELS_TIP );
728 _options_jmenu.add( _abbreviate_scientific_names = new JCheckBoxMenuItem( MainFrame.ABBREV_SN_LABEL ) );
729 _options_jmenu.add( _label_direction_cbmi = new JCheckBoxMenuItem( MainFrame.LABEL_DIRECTION_LABEL ) );
730 _label_direction_cbmi.setToolTipText( MainFrame.LABEL_DIRECTION_TIP );
731 _options_jmenu.add( _screen_antialias_cbmi = new JCheckBoxMenuItem( MainFrame.SCREEN_ANTIALIAS_LABEL ) );
732 _options_jmenu.add( _background_gradient_cbmi = new JCheckBoxMenuItem( MainFrame.BG_GRAD_LABEL ) );
733 _options_jmenu.add( _cycle_node_shape_mi = new JMenuItem( MainFrame.CYCLE_NODE_SHAPE_LABEL ) );
734 _options_jmenu.add( _cycle_node_fill_mi = new JMenuItem( MainFrame.CYCLE_NODE_FILL_LABEL ) );
735 _options_jmenu.add( _choose_node_size_mi = new JMenuItem( MainFrame.CHOOSE_NODE_SIZE_LABEL ) );
736 _options_jmenu.add( _choose_minimal_confidence_mi = new JMenuItem( "" ) );
737 _options_jmenu.add( _overview_placment_mi = new JMenuItem( "" ) );
738 _options_jmenu.add( _switch_colors_mi = new JMenuItem( "" ) );
739 _options_jmenu.add( _choose_font_mi = new JMenuItem( "" ) );
741 _options_jmenu.addSeparator();
742 _options_jmenu.add( MainFrame.customizeMenuItemAsLabel( new JMenuItem( MainFrame.SEARCH_SUBHEADER ),
743 getConfiguration() ) );
745 .add( _search_case_senstive_cbmi = new JCheckBoxMenuItem( MainFrame.SEARCH_CASE_SENSITIVE_LABEL ) );
746 _options_jmenu.add( _search_whole_words_only_cbmi = new JCheckBoxMenuItem( MainFrame.SEARCH_TERMS_ONLY_LABEL ) );
748 .add( _inverse_search_result_cbmi = new JCheckBoxMenuItem( MainFrame.INVERSE_SEARCH_RESULT_LABEL ) );
749 customizeJMenuItem( _choose_font_mi );
750 customizeJMenuItem( _choose_minimal_confidence_mi );
751 customizeJMenuItem( _switch_colors_mi );
752 customizeJMenuItem( _overview_placment_mi );
753 customizeCheckBoxMenuItem( _color_by_taxonomic_group_cbmi, getOptions().isColorByTaxonomicGroup() );
754 customizeCheckBoxMenuItem( _label_direction_cbmi,
755 getOptions().getNodeLabelDirection() == NODE_LABEL_DIRECTION.RADIAL );
756 customizeCheckBoxMenuItem( _screen_antialias_cbmi, getOptions().isAntialiasScreen() );
757 customizeCheckBoxMenuItem( _background_gradient_cbmi, getOptions().isBackgroundColorGradient() );
758 customizeCheckBoxMenuItem( _show_domain_labels, getOptions().isShowDomainLabels() );
759 customizeCheckBoxMenuItem( _show_annotation_ref_source, getOptions().isShowAnnotationRefSource() );
760 customizeCheckBoxMenuItem( _abbreviate_scientific_names, getOptions().isAbbreviateScientificTaxonNames() );
761 customizeCheckBoxMenuItem( _show_default_node_shapes_external_cbmi, getOptions()
762 .isShowDefaultNodeShapesExternal() );
763 customizeCheckBoxMenuItem( _show_default_node_shapes_internal_cbmi, getOptions()
764 .isShowDefaultNodeShapesInternal() );
765 customizeCheckBoxMenuItem( _taxonomy_colorize_node_shapes_cbmi, getOptions().isTaxonomyColorizeNodeShapes() );
766 customizeJMenuItem( _cycle_node_shape_mi );
767 customizeJMenuItem( _cycle_node_fill_mi );
768 customizeJMenuItem( _choose_node_size_mi );
769 customizeCheckBoxMenuItem( _color_labels_same_as_parent_branch, getOptions().isColorLabelsSameAsParentBranch() );
770 customizeCheckBoxMenuItem( _search_case_senstive_cbmi, getOptions().isSearchCaseSensitive() );
771 customizeCheckBoxMenuItem( _show_scale_cbmi, getOptions().isShowScale() );
772 customizeRadioButtonMenuItem( _non_lined_up_cladograms_rbmi,
773 getOptions().getCladogramType() == CLADOGRAM_TYPE.NON_LINED_UP );
774 customizeRadioButtonMenuItem( _uniform_cladograms_rbmi,
775 getOptions().getCladogramType() == CLADOGRAM_TYPE.TOTAL_NODE_SUM_DEP );
776 customizeRadioButtonMenuItem( _ext_node_dependent_cladogram_rbmi,
777 getOptions().getCladogramType() == CLADOGRAM_TYPE.EXT_NODE_SUM_DEP );
778 customizeCheckBoxMenuItem( _show_branch_length_values_cbmi, getOptions().isShowBranchLengthValues() );
779 customizeCheckBoxMenuItem( _show_overview_cbmi, getOptions().isShowOverview() );
780 customizeCheckBoxMenuItem( _search_whole_words_only_cbmi, getOptions().isMatchWholeTermsOnly() );
781 customizeCheckBoxMenuItem( _inverse_search_result_cbmi, getOptions().isInverseSearchResult() );
782 customizeCheckBoxMenuItem( _show_confidence_stddev_cbmi, getOptions().isShowConfidenceStddev() );
783 _jmenubar.add( _options_jmenu );
786 void buildToolsMenu() {
787 _tools_menu = MainFrame.createMenu( "Tools", getConfiguration() );
788 _tools_menu.add( _confcolor_item = new JMenuItem( "Colorize Branches Depending on Confidence" ) );
789 customizeJMenuItem( _confcolor_item );
790 _tools_menu.add( _taxcolor_item = new JMenuItem( "Taxonomy Colorize Branches" ) );
791 customizeJMenuItem( _taxcolor_item );
792 _tools_menu.add( _remove_branch_color_item = new JMenuItem( "Delete Branch Colors" ) );
793 _remove_branch_color_item.setToolTipText( "To delete branch color values from the current phylogeny." );
794 customizeJMenuItem( _remove_branch_color_item );
795 _tools_menu.addSeparator();
796 _tools_menu.add( _midpoint_root_item = new JMenuItem( "Midpoint-Root" ) );
797 customizeJMenuItem( _midpoint_root_item );
798 _tools_menu.addSeparator();
799 _tools_menu.add( _collapse_species_specific_subtrees = new JMenuItem( "Collapse Species-Specific Subtrees" ) );
800 customizeJMenuItem( _collapse_species_specific_subtrees );
801 _jmenubar.add( _tools_menu );
804 void buildTypeMenu() {
805 _type_menu = MainFrame.createMenu( MainFrame.TYPE_MENU_HEADER, getConfiguration() );
806 _type_menu.add( _rectangular_type_cbmi = new JCheckBoxMenuItem( MainFrame.RECTANGULAR_TYPE_CBMI_LABEL ) );
807 _type_menu.add( _euro_type_cbmi = new JCheckBoxMenuItem( MainFrame.EURO_TYPE_CBMI_LABEL ) );
808 _type_menu.add( _rounded_type_cbmi = new JCheckBoxMenuItem( MainFrame.ROUNDED_TYPE_CBMI_LABEL ) );
809 _type_menu.add( _curved_type_cbmi = new JCheckBoxMenuItem( MainFrame.CURVED_TYPE_CBMI_LABEL ) );
810 _type_menu.add( _triangular_type_cbmi = new JCheckBoxMenuItem( MainFrame.TRIANGULAR_TYPE_CBMI_LABEL ) );
811 _type_menu.add( _convex_type_cbmi = new JCheckBoxMenuItem( MainFrame.CONVEX_TYPE_CBMI_LABEL ) );
812 _type_menu.add( _unrooted_type_cbmi = new JCheckBoxMenuItem( MainFrame.UNROOTED_TYPE_CBMI_LABEL ) );
813 _type_menu.add( _circular_type_cbmi = new JCheckBoxMenuItem( MainFrame.CIRCULAR_TYPE_CBMI_LABEL ) );
814 customizeCheckBoxMenuItem( _rectangular_type_cbmi, false );
815 customizeCheckBoxMenuItem( _triangular_type_cbmi, false );
816 customizeCheckBoxMenuItem( _euro_type_cbmi, false );
817 customizeCheckBoxMenuItem( _rounded_type_cbmi, false );
818 customizeCheckBoxMenuItem( _curved_type_cbmi, false );
819 customizeCheckBoxMenuItem( _convex_type_cbmi, false );
820 customizeCheckBoxMenuItem( _unrooted_type_cbmi, false );
821 customizeCheckBoxMenuItem( _circular_type_cbmi, false );
822 _unrooted_type_cbmi.setToolTipText( MainFrame.USE_MOUSEWHEEL_SHIFT_TO_ROTATE );
823 _circular_type_cbmi.setToolTipText( MainFrame.USE_MOUSEWHEEL_SHIFT_TO_ROTATE );
824 initializeTypeMenu( getOptions() );
825 _jmenubar.add( _type_menu );
828 void buildViewMenu() {
829 _view_jmenu = MainFrame.createMenu( "View", getConfiguration() );
831 .add( _display_basic_information_item = new JMenuItem( MainFrame.SHOW_BASIC_TREE_INFORMATION_LABEL ) );
832 _view_jmenu.addSeparator();
833 _view_jmenu.add( _view_as_XML_item = new JMenuItem( "as phyloXML" ) );
834 _view_jmenu.add( _view_as_NH_item = new JMenuItem( "as Newick" ) );
835 _view_jmenu.add( _view_as_nexus_item = new JMenuItem( "as Nexus" ) );
836 customizeJMenuItem( _display_basic_information_item );
837 customizeJMenuItem( _view_as_NH_item );
838 customizeJMenuItem( _view_as_XML_item );
839 customizeJMenuItem( _view_as_nexus_item );
840 _jmenubar.add( _view_jmenu );
843 void checkTextFrames() {
844 if ( _textframes.size() > 5 ) {
846 if ( _textframes.getFirst() != null ) {
847 _textframes.getFirst().removeMe();
850 _textframes.removeFirst();
853 catch ( final NoSuchElementException e ) {
859 void clearCurrentExternalNodesDataBuffer() {
860 getCurrentTreePanel().clearCurrentExternalNodesDataBuffer();
863 void customizeCheckBoxMenuItem( final JCheckBoxMenuItem item, final boolean is_selected ) {
864 if ( item != null ) {
865 item.setFont( MainFrame.menu_font );
866 if ( !getConfiguration().isUseNativeUI() ) {
867 item.setBackground( getConfiguration().getGuiMenuBackgroundColor() );
868 item.setForeground( getConfiguration().getGuiMenuTextColor() );
870 item.setSelected( is_selected );
871 item.addActionListener( this );
875 void customizeJMenuItem( final JMenuItem jmi ) {
876 jmi.setFont( MainFrame.menu_font );
877 if ( !getConfiguration().isUseNativeUI() ) {
878 jmi.setBackground( getConfiguration().getGuiMenuBackgroundColor() );
879 jmi.setForeground( getConfiguration().getGuiMenuTextColor() );
881 jmi.addActionListener( this );
884 void displayBasicInformation() {
885 if ( ( getMainPanel().getCurrentPhylogeny() != null ) && !getMainPanel().getCurrentPhylogeny().isEmpty() ) {
886 String title = "Basic Information";
887 if ( !ForesterUtil.isEmpty( getMainPanel().getCurrentPhylogeny().getName() ) ) {
888 title = title + " for \"" + _mainpanel.getCurrentPhylogeny().getName() + "\"";
890 showTextFrame( AptxUtil.createBasicInformation( getMainPanel().getCurrentPhylogeny(), null ), title );
895 if ( !isOKforSDI( false, true ) ) {
898 if ( !_mainpanel.getCurrentPhylogeny().isRooted() ) {
899 JOptionPane.showMessageDialog( this,
900 "Gene tree is not rooted.",
901 "Cannot execute GSDI",
902 JOptionPane.ERROR_MESSAGE );
905 final Phylogeny gene_tree = _mainpanel.getCurrentPhylogeny().copy();
906 gene_tree.setAllNodesToNotCollapse();
907 gene_tree.recalculateNumberOfExternalDescendants( false );
909 final Phylogeny species_tree = _species_tree.copy();
911 gsdi = new GSDI( gene_tree, species_tree, false, true, true, true );
913 catch ( final SDIException e ) {
914 JOptionPane.showMessageDialog( this,
915 e.getLocalizedMessage(),
917 JOptionPane.ERROR_MESSAGE );
920 catch ( final Exception e ) {
921 AptxUtil.unexpectedException( e );
924 gene_tree.setRerootable( false );
925 gene_tree.clearHashIdToNodeMap();
926 gene_tree.recalculateNumberOfExternalDescendants( true );
927 _mainpanel.addPhylogenyInNewTab( gene_tree, getConfiguration(), "gene tree", null );
928 getMainPanel().getControlPanel().setShowEvents( true );
930 final int selected = _mainpanel.getTabbedPane().getSelectedIndex();
931 _mainpanel.addPhylogenyInNewTab( species_tree, getConfiguration(), "species tree", null );
933 _mainpanel.getTabbedPane().setSelectedIndex( selected );
935 _mainpanel.getCurrentTreePanel().setEdited( true );
936 final int poly = PhylogenyMethods.countNumberOfPolytomies( species_tree );
937 if ( gsdi.getStrippedExternalGeneTreeNodes().size() > 0 ) {
938 JOptionPane.showMessageDialog( this,
939 "Duplications: " + gsdi.getDuplicationsSum() + "\n"
940 + "Potential duplications: "
941 + gsdi.getSpeciationOrDuplicationEventsSum() + "\n"
942 + "Speciations: " + gsdi.getSpeciationsSum() + "\n"
943 + "Stripped gene tree nodes: "
944 + gsdi.getStrippedExternalGeneTreeNodes().size() + "\n"
945 + "Taxonomy linkage based on: " + gsdi.getTaxCompBase() + "\n"
946 + "Number of polytomies in species tree used: " + poly + "\n",
947 "GSDI successfully completed",
948 JOptionPane.WARNING_MESSAGE );
951 JOptionPane.showMessageDialog( this,
952 "Duplications: " + gsdi.getDuplicationsSum() + "\n"
953 + "Potential duplications: "
954 + gsdi.getSpeciationOrDuplicationEventsSum() + "\n"
955 + "Speciations: " + gsdi.getSpeciationsSum() + "\n"
956 + "Stripped gene tree nodes: "
957 + gsdi.getStrippedExternalGeneTreeNodes().size() + "\n"
958 + "Taxonomy linkage based on: " + gsdi.getTaxCompBase() + "\n"
959 + "Number of polytomies in species tree used: " + poly + "\n",
960 "GSDI successfully completed",
961 JOptionPane.INFORMATION_MESSAGE );
965 void executeGSDIR() {
966 if ( !isOKforSDI( false, false ) ) {
969 final int p = PhylogenyMethods.countNumberOfPolytomies( _mainpanel.getCurrentPhylogeny() );
971 && !( ( p == 1 ) && ( _mainpanel.getCurrentPhylogeny().getRoot().getNumberOfDescendants() == 3 ) ) ) {
972 JOptionPane.showMessageDialog( this,
973 "Gene tree is not completely binary",
974 "Cannot execute GSDI",
975 JOptionPane.ERROR_MESSAGE );
978 final Phylogeny gene_tree = _mainpanel.getCurrentPhylogeny().copy();
979 gene_tree.setAllNodesToNotCollapse();
980 gene_tree.recalculateNumberOfExternalDescendants( false );
982 final Phylogeny species_tree = _species_tree.copy();
984 gsdir = new GSDIR( gene_tree, species_tree, true, true, true );
986 catch ( final SDIException e ) {
987 JOptionPane.showMessageDialog( this,
988 e.getLocalizedMessage(),
989 "Error during GSDIR",
990 JOptionPane.ERROR_MESSAGE );
993 catch ( final Exception e ) {
994 AptxUtil.unexpectedException( e );
997 final Phylogeny result_gene_tree = gsdir.getMinDuplicationsSumGeneTree();
998 result_gene_tree.setRerootable( false );
999 result_gene_tree.clearHashIdToNodeMap();
1000 result_gene_tree.recalculateNumberOfExternalDescendants( true );
1001 PhylogenyMethods.orderAppearance( result_gene_tree.getRoot(), true, true, DESCENDANT_SORT_PRIORITY.NODE_NAME );
1002 _mainpanel.addPhylogenyInNewTab( result_gene_tree, getConfiguration(), "gene tree", null );
1003 getMainPanel().getControlPanel().setShowEvents( true );
1005 final int selected = _mainpanel.getTabbedPane().getSelectedIndex();
1006 _mainpanel.addPhylogenyInNewTab( species_tree, getConfiguration(), "species tree", null );
1008 _mainpanel.getTabbedPane().setSelectedIndex( selected );
1010 _mainpanel.getCurrentTreePanel().setEdited( true );
1011 final int poly = PhylogenyMethods.countNumberOfPolytomies( species_tree );
1012 if ( gsdir.getStrippedExternalGeneTreeNodes().size() > 0 ) {
1013 JOptionPane.showMessageDialog( this,
1014 "Minimal duplications: " + gsdir.getMinDuplicationsSum() + "\n"
1015 + "Speciations: " + gsdir.getSpeciationsSum() + "\n"
1016 + "Stripped gene tree nodes: "
1017 + gsdir.getStrippedExternalGeneTreeNodes().size() + "\n"
1018 + "Taxonomy linkage based on: " + gsdir.getTaxCompBase() + "\n"
1019 + "Number of polytomies in species tree used: " + poly + "\n",
1020 "GSDIR successfully completed",
1021 JOptionPane.WARNING_MESSAGE );
1024 JOptionPane.showMessageDialog( this,
1025 "Minimal duplications: " + gsdir.getMinDuplicationsSum() + "\n"
1026 + "Speciations: " + gsdir.getSpeciationsSum() + "\n"
1027 + "Stripped gene tree nodes: "
1028 + gsdir.getStrippedExternalGeneTreeNodes().size() + "\n"
1029 + "Taxonomy linkage based on: " + gsdir.getTaxCompBase() + "\n"
1030 + "Number of polytomies in species tree used: " + poly + "\n",
1031 "GSDIR successfully completed",
1032 JOptionPane.INFORMATION_MESSAGE );
1036 Configuration getConfiguration() {
1037 return _configuration;
1040 TreePanel getCurrentTreePanel() {
1041 return getMainPanel().getCurrentTreePanel();
1044 JCheckBoxMenuItem getlabelDirectionCbmi() {
1045 return _label_direction_cbmi;
1048 Options getOtions() {
1053 final StringBuilder sb = new StringBuilder();
1054 sb.append( "Display options\n" );
1055 sb.append( "-------------------\n" );
1056 sb.append( "Use the checkboxes to select types of information to display on the tree.\n\n" );
1057 sb.append( "Clickable tree nodes\n" );
1058 sb.append( "--------------------\n" );
1059 sb.append( "Tree nodes can be clicked, the action is determined by the 'click on node to' menu\n" );
1060 sb.append( "or by right clicking:\n" );
1061 sb.append( "o Display Node Data -- display information for a node\n" );
1062 sb.append( "o Collapse/Uncollapse -- collapse and uncollapse subtree from clicked node\n" );
1063 sb.append( "o Root/Reroot -- change tree root to clicked node\n" );
1064 sb.append( "o Sub/Super Tree -- toggle between subtree from clicked node and whole tree\n" );
1065 sb.append( "o Swap Descendants -- switch descendant on either side of clicked node\n" );
1066 sb.append( "o Colorize Subtree -- color a subtree\n" );
1067 sb.append( "o Open Sequence Web -- launch a web browser to display sequence information\n" );
1068 sb.append( "o Open Taxonomy Web -- launch a web browser to display taxonomy information\n" );
1069 sb.append( "- there may be additional choices depending on this particular setup\n\n" );
1070 sb.append( "Right clicking on a node always displays the information of a node.\n\n" );
1071 sb.append( "Zooming\n" );
1072 sb.append( "---------\n" );
1073 sb.append( "The mouse wheel and the plus and minus keys control zooming.\n" );
1074 sb.append( "Mouse wheel+Ctrl changes the text size.\n" );
1075 sb.append( "Mouse wheel+Shift controls zooming in vertical direction only.\n" );
1076 sb.append( "Use the buttons on the control panel to zoom the tree in and out, horizontally or vertically.\n" );
1077 sb.append( "The entire tree can be fitted into the window by clicking the \"F\" button, or by pressing F, Delete, or Home.\n" );
1078 sb.append( "The up, down, left, and right keys can be used to move the visible part (if zoomed in).\n" );
1079 sb.append( "Up, down, left, and right+Shift can be used to control zooming horizontally and vertically.\n" );
1080 sb.append( "Plus and minus keys+Ctrl change the text size; F+Ctrl, Delete+Ctrl, or Home+Ctrl resets it.\n\n" );
1081 sb.append( "Quick tree manipulation:\n" );
1082 sb.append( "------------------------\n" );
1083 sb.append( "Order Subtrees -- order the tree by branch length\n" );
1084 sb.append( "Uncollapse All -- uncollapse any and all collapsed branches\n\n" );
1085 sb.append( "phyloXML\n" );
1086 sb.append( "-------------------\n" );
1087 sb.append( "Reference: " + Constants.PHYLOXML_REFERENCE + "\n" );
1088 sb.append( "Website: " + Constants.PHYLOXML_WEB_SITE + "\n" );
1089 sb.append( "Version: " + ForesterConstants.PHYLO_XML_VERSION + "\n" );
1091 sb.append( "For more information: http://www.phylosoft.org/archaeopteryx/\n" );
1092 sb.append( "Email: " + Constants.AUTHOR_EMAIL + "\n\n" );
1093 TextFrame.instantiate( sb.toString(), "Help", _textframes );
1096 void initializeTypeMenu( final Options options ) {
1097 setTypeMenuToAllUnselected();
1099 switch ( options.getPhylogenyGraphicsType() ) {
1101 _convex_type_cbmi.setSelected( true );
1104 _curved_type_cbmi.setSelected( true );
1107 _euro_type_cbmi.setSelected( true );
1110 _rounded_type_cbmi.setSelected( true );
1113 _triangular_type_cbmi.setSelected( true );
1116 _unrooted_type_cbmi.setSelected( true );
1119 _circular_type_cbmi.setSelected( true );
1122 _rectangular_type_cbmi.setSelected( true );
1126 catch ( final NullPointerException np ) {
1127 // In all likelihood, this is caused by menu-less display.
1131 boolean isOKforSDI( final boolean species_tree_has_to_binary, final boolean gene_tree_has_to_binary ) {
1132 if ( ( _mainpanel.getCurrentPhylogeny() == null ) || _mainpanel.getCurrentPhylogeny().isEmpty() ) {
1135 else if ( ( _species_tree == null ) || _species_tree.isEmpty() ) {
1136 JOptionPane.showMessageDialog( this,
1137 "No species tree loaded",
1138 "Cannot execute GSDI",
1139 JOptionPane.ERROR_MESSAGE );
1142 else if ( species_tree_has_to_binary && !_species_tree.isCompletelyBinary() ) {
1143 JOptionPane.showMessageDialog( this,
1144 "Species tree is not completely binary",
1145 "Cannot execute GSDI",
1146 JOptionPane.ERROR_MESSAGE );
1149 else if ( gene_tree_has_to_binary && !_mainpanel.getCurrentPhylogeny().isCompletelyBinary() ) {
1150 JOptionPane.showMessageDialog( this,
1151 "Gene tree is not completely binary",
1152 "Cannot execute GSDI",
1153 JOptionPane.ERROR_MESSAGE );
1161 boolean isSubtreeDisplayed() {
1162 if ( getCurrentTreePanel() != null ) {
1163 if ( getCurrentTreePanel().isCurrentTreeIsSubtree() ) {
1165 .showMessageDialog( this,
1166 "This operation can only be performed on a complete tree, not on the currently displayed sub-tree only.",
1167 "Operation can not be exectuted on a sub-tree",
1168 JOptionPane.WARNING_MESSAGE );
1175 void removeAllTextFrames() {
1176 for( final TextFrame tf : _textframes ) {
1181 _textframes.clear();
1184 void setConfiguration( final Configuration configuration ) {
1185 _configuration = configuration;
1188 void setOptions( final Options options ) {
1192 void setSelectedTypeInTypeMenu( final PHYLOGENY_GRAPHICS_TYPE type ) {
1193 setTypeMenuToAllUnselected();
1197 _circular_type_cbmi.setSelected( true );
1200 _convex_type_cbmi.setSelected( true );
1203 _curved_type_cbmi.setSelected( true );
1206 _euro_type_cbmi.setSelected( true );
1209 _rounded_type_cbmi.setSelected( true );
1212 _rectangular_type_cbmi.setSelected( true );
1215 _triangular_type_cbmi.setSelected( true );
1218 _unrooted_type_cbmi.setSelected( true );
1221 throw new IllegalArgumentException( "unknown type: " + type );
1224 catch ( final NullPointerException np ) {
1225 // In all likelihood, this is caused by menu-less display.
1229 void setTypeMenuToAllUnselected() {
1230 if ( _convex_type_cbmi != null ) {
1231 _convex_type_cbmi.setSelected( false );
1233 if ( _curved_type_cbmi != null ) {
1234 _curved_type_cbmi.setSelected( false );
1236 if ( _euro_type_cbmi != null ) {
1237 _euro_type_cbmi.setSelected( false );
1239 if ( _rounded_type_cbmi != null ) {
1240 _rounded_type_cbmi.setSelected( false );
1242 if ( _triangular_type_cbmi != null ) {
1243 _triangular_type_cbmi.setSelected( false );
1245 if ( _rectangular_type_cbmi != null ) {
1246 _rectangular_type_cbmi.setSelected( false );
1248 if ( _unrooted_type_cbmi != null ) {
1249 _unrooted_type_cbmi.setSelected( false );
1251 if ( _circular_type_cbmi != null ) {
1252 _circular_type_cbmi.setSelected( false );
1257 _mainpanel.getControlPanel().showWhole();
1260 void switchColors() {
1261 final TreeColorSet colorset = getMainPanel().getCurrentTreePanel().getTreeColorSet();
1262 final ColorSchemeChooser csc = new ColorSchemeChooser( getMainPanel(), colorset );
1263 csc.setVisible( true );
1264 getMainPanel().setTreeColorSet( colorset );
1267 void typeChanged( final Object o ) {
1268 updateTypeCheckboxes( getOptions(), o );
1269 updateOptions( getOptions() );
1270 if ( getCurrentTreePanel() != null ) {
1271 final PHYLOGENY_GRAPHICS_TYPE previous_type = getCurrentTreePanel().getPhylogenyGraphicsType();
1272 final PHYLOGENY_GRAPHICS_TYPE new_type = getOptions().getPhylogenyGraphicsType();
1273 if ( ( ( previous_type == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) && ( new_type != PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) )
1274 || ( ( previous_type == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) && ( new_type != PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) )
1275 || ( ( previous_type != PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) && ( new_type == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) )
1276 || ( ( previous_type != PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) && ( new_type == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) ) ) {
1277 getCurrentTreePanel().getControlPanel().showWhole();
1279 if ( getCurrentTreePanel().isPhyHasBranchLengths() && ( new_type != PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) ) {
1280 getCurrentTreePanel().getControlPanel().setDrawPhylogramEnabled( true );
1283 getCurrentTreePanel().getControlPanel().setDrawPhylogramEnabled( false );
1285 getCurrentTreePanel().setPhylogenyGraphicsType( getOptions().getPhylogenyGraphicsType() );
1286 MainFrame.updateScreenTextAntialias( getMainPanel().getTreePanels() );
1290 void updateOptions( final Options options ) {
1291 options.setAntialiasScreen( ( _screen_antialias_cbmi != null ) && _screen_antialias_cbmi.isSelected() );
1292 options.setBackgroundColorGradient( ( _background_gradient_cbmi != null )
1293 && _background_gradient_cbmi.isSelected() );
1294 options.setShowDomainLabels( ( _show_domain_labels != null ) && _show_domain_labels.isSelected() );
1295 options.setShowAnnotationRefSource( ( _show_annotation_ref_source != null )
1296 && _show_annotation_ref_source.isSelected() );
1297 options.setAbbreviateScientificTaxonNames( ( _abbreviate_scientific_names != null )
1298 && _abbreviate_scientific_names.isSelected() );
1299 options.setColorLabelsSameAsParentBranch( ( _color_labels_same_as_parent_branch != null )
1300 && _color_labels_same_as_parent_branch.isSelected() );
1301 options.setShowDefaultNodeShapesInternal( ( _show_default_node_shapes_internal_cbmi != null )
1302 && _show_default_node_shapes_internal_cbmi.isSelected() );
1303 options.setShowDefaultNodeShapesExternal( ( _show_default_node_shapes_external_cbmi != null )
1304 && _show_default_node_shapes_external_cbmi.isSelected() );
1305 options.setTaxonomyColorizeNodeShapes( ( _taxonomy_colorize_node_shapes_cbmi != null )
1306 && _taxonomy_colorize_node_shapes_cbmi.isSelected() );
1307 if ( ( _non_lined_up_cladograms_rbmi != null ) && ( _non_lined_up_cladograms_rbmi.isSelected() ) ) {
1308 options.setCladogramType( CLADOGRAM_TYPE.NON_LINED_UP );
1310 else if ( ( _uniform_cladograms_rbmi != null ) && ( _uniform_cladograms_rbmi.isSelected() ) ) {
1311 options.setCladogramType( CLADOGRAM_TYPE.TOTAL_NODE_SUM_DEP );
1313 else if ( ( _ext_node_dependent_cladogram_rbmi != null ) && ( _ext_node_dependent_cladogram_rbmi.isSelected() ) ) {
1314 options.setCladogramType( CLADOGRAM_TYPE.EXT_NODE_SUM_DEP );
1316 options.setSearchCaseSensitive( ( _search_case_senstive_cbmi != null )
1317 && _search_case_senstive_cbmi.isSelected() );
1318 if ( ( _show_scale_cbmi != null ) && _show_scale_cbmi.isEnabled() ) {
1319 options.setShowScale( _show_scale_cbmi.isSelected() );
1321 if ( _label_direction_cbmi != null ) {
1322 if ( _label_direction_cbmi.isSelected() ) {
1323 options.setNodeLabelDirection( NODE_LABEL_DIRECTION.RADIAL );
1326 options.setNodeLabelDirection( NODE_LABEL_DIRECTION.HORIZONTAL );
1329 options.setShowOverview( ( _show_overview_cbmi != null ) && _show_overview_cbmi.isSelected() );
1330 options.setShowConfidenceStddev( ( _show_confidence_stddev_cbmi != null )
1331 && _show_confidence_stddev_cbmi.isSelected() );
1332 if ( ( _show_branch_length_values_cbmi != null ) && _show_branch_length_values_cbmi.isEnabled() ) {
1333 options.setShowBranchLengthValues( _show_branch_length_values_cbmi.isSelected() );
1335 options.setMatchWholeTermsOnly( ( _search_whole_words_only_cbmi != null )
1336 && _search_whole_words_only_cbmi.isSelected() );
1337 options.setInverseSearchResult( ( _inverse_search_result_cbmi != null )
1338 && _inverse_search_result_cbmi.isSelected() );
1339 if ( ( _rectangular_type_cbmi != null ) && _rectangular_type_cbmi.isSelected() ) {
1340 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR );
1342 else if ( ( _triangular_type_cbmi != null ) && _triangular_type_cbmi.isSelected() ) {
1343 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.TRIANGULAR );
1345 else if ( ( _curved_type_cbmi != null ) && _curved_type_cbmi.isSelected() ) {
1346 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CURVED );
1348 else if ( ( _convex_type_cbmi != null ) && _convex_type_cbmi.isSelected() ) {
1349 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CONVEX );
1351 else if ( ( _euro_type_cbmi != null ) && _euro_type_cbmi.isSelected() ) {
1352 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE );
1354 else if ( ( _rounded_type_cbmi != null ) && _rounded_type_cbmi.isSelected() ) {
1355 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.ROUNDED );
1357 else if ( ( _unrooted_type_cbmi != null ) && _unrooted_type_cbmi.isSelected() ) {
1358 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.UNROOTED );
1360 else if ( ( _circular_type_cbmi != null ) && _circular_type_cbmi.isSelected() ) {
1361 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CIRCULAR );
1363 if ( ( _color_by_taxonomic_group_cbmi != null ) && _color_by_taxonomic_group_cbmi.isEnabled() ) {
1364 options.setColorByTaxonomicGroup( _color_by_taxonomic_group_cbmi.isSelected() );
1368 void updateTypeCheckboxes( final Options options, final Object o ) {
1369 setTypeMenuToAllUnselected();
1370 ( ( JCheckBoxMenuItem ) o ).setSelected( true );
1373 void viewAsNexus() {
1374 if ( ( getMainPanel().getCurrentPhylogeny() != null ) && !getMainPanel().getCurrentPhylogeny().isEmpty() ) {
1375 String title = "Nexus";
1376 if ( !ForesterUtil.isEmpty( getMainPanel().getCurrentPhylogeny().getName() ) ) {
1377 title = "\"" + getMainPanel().getCurrentPhylogeny().getName() + "\" in " + title;
1379 showTextFrame( getMainPanel().getCurrentPhylogeny().toNexus( getOptions()
1380 .getNhConversionSupportValueStyle() ),
1386 if ( ( getMainPanel().getCurrentPhylogeny() != null ) && !getMainPanel().getCurrentPhylogeny().isEmpty() ) {
1387 String title = "New Hampshire";
1388 if ( !ForesterUtil.isEmpty( getMainPanel().getCurrentPhylogeny().getName() ) ) {
1389 title = "\"" + getMainPanel().getCurrentPhylogeny().getName() + "\" in " + title;
1391 showTextFrame( getMainPanel().getCurrentPhylogeny()
1392 .toNewHampshire( false, getOptions().getNhConversionSupportValueStyle() ),
1398 if ( ( getMainPanel().getCurrentPhylogeny() != null ) && !getMainPanel().getCurrentPhylogeny().isEmpty() ) {
1399 String title = "phyloXML";
1400 if ( !ForesterUtil.isEmpty( getMainPanel().getCurrentPhylogeny().getName() ) ) {
1401 title = "\"" + getMainPanel().getCurrentPhylogeny().getName() + "\" in " + title;
1403 showTextFrame( getMainPanel().getCurrentPhylogeny().toPhyloXML( 0 ), title );
1407 private void chooseFont() {
1408 final FontChooser fc = new FontChooser();
1409 fc.setFont( getMainPanel().getTreeFontSet().getLargeFont() );
1410 fc.showDialog( this, "Select the Base Font" );
1411 getMainPanel().getTreeFontSet().setBaseFont( fc.getFont() );
1414 private void chooseMinimalConfidence() {
1415 final String s = ( String ) JOptionPane
1416 .showInputDialog( this,
1417 "Please the minimum for confidence values to be displayed.\n" + "[current value: "
1418 + getOptions().getMinConfidenceValue() + "]\n",
1419 "Minimal Confidence Value",
1420 JOptionPane.QUESTION_MESSAGE,
1423 getOptions().getMinConfidenceValue() );
1424 if ( !ForesterUtil.isEmpty( s ) ) {
1425 boolean success = true;
1427 final String m_str = s.trim();
1428 if ( !ForesterUtil.isEmpty( m_str ) ) {
1430 m = Double.parseDouble( m_str );
1432 catch ( final Exception ex ) {
1439 if ( success && ( m >= 0.0 ) ) {
1440 getOptions().setMinConfidenceValue( m );
1445 private void customizeRadioButtonMenuItem( final JRadioButtonMenuItem item, final boolean is_selected ) {
1446 if ( item != null ) {
1447 item.setFont( MainFrame.menu_font );
1448 if ( !getConfiguration().isUseNativeUI() ) {
1449 item.setBackground( getConfiguration().getGuiMenuBackgroundColor() );
1450 item.setForeground( getConfiguration().getGuiMenuTextColor() );
1452 item.setSelected( is_selected );
1453 item.addActionListener( this );
1457 private MainPanel getMainPanel() {
1461 private Phylogeny getSpeciesTree() {
1462 return _species_tree;
1465 private boolean isScreenAntialias() {
1469 private void removeBranchColors() {
1470 if ( getMainPanel().getCurrentPhylogeny() != null ) {
1471 AptxUtil.removeBranchColors( getMainPanel().getCurrentPhylogeny() );
1475 private void setMainPanel( final MainPanelApplets main_panel ) {
1476 _mainpanel = main_panel;
1479 private void setSpeciesTree( final Phylogeny species_tree ) {
1480 _species_tree = species_tree;
1483 private void setupUI() {
1485 if ( getConfiguration().isUseNativeUI() ) {
1486 UIManager.setLookAndFeel( UIManager.getSystemLookAndFeelClassName() );
1489 UIManager.setLookAndFeel( UIManager.getCrossPlatformLookAndFeelClassName() );
1492 catch ( final UnsupportedLookAndFeelException e ) {
1493 AptxUtil.dieWithSystemError( "UnsupportedLookAndFeelException: " + e.toString() );
1495 catch ( final ClassNotFoundException e ) {
1496 AptxUtil.dieWithSystemError( "ClassNotFoundException: " + e.toString() );
1498 catch ( final InstantiationException e ) {
1499 AptxUtil.dieWithSystemError( "InstantiationException: " + e.toString() );
1501 catch ( final IllegalAccessException e ) {
1502 AptxUtil.dieWithSystemError( "IllegalAccessException: " + e.toString() );
1504 catch ( final Exception e ) {
1505 AptxUtil.dieWithSystemError( e.toString() );
1509 static void setupScreenTextAntialias( final List<TreePanel> treepanels, final boolean antialias ) {
1510 for( final TreePanel tree_panel : treepanels ) {
1511 tree_panel.setTextAntialias();