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().search0();
246 getMainPanel().getControlPanel().search1();
248 else if ( o == _search_whole_words_only_cbmi ) {
249 updateOptions( getOptions() );
250 getMainPanel().getControlPanel().search0();
251 getMainPanel().getControlPanel().search1();
253 else if ( o == _inverse_search_result_cbmi ) {
254 updateOptions( getOptions() );
255 getMainPanel().getControlPanel().search0();
256 getMainPanel().getControlPanel().search1();
258 else if ( o == _show_scale_cbmi ) {
259 updateOptions( getOptions() );
261 else if ( o == _show_branch_length_values_cbmi ) {
262 updateOptions( getOptions() );
264 else if ( o == _show_confidence_stddev_cbmi ) {
265 updateOptions( getOptions() );
267 else if ( o == _label_direction_cbmi ) {
268 updateOptions( getOptions() );
270 else if ( o == _abbreviate_scientific_names ) {
271 updateOptions( getOptions() );
273 else if ( o == _show_overview_cbmi ) {
274 updateOptions( getOptions() );
275 if ( getCurrentTreePanel() != null ) {
276 getCurrentTreePanel().updateOvSizes();
279 else if ( ( o == _rectangular_type_cbmi ) || ( o == _triangular_type_cbmi ) || ( o == _curved_type_cbmi )
280 || ( o == _convex_type_cbmi ) || ( o == _rounded_type_cbmi ) || ( o == _euro_type_cbmi )
281 || ( o == _unrooted_type_cbmi ) || ( o == _circular_type_cbmi ) ) {
284 else if ( o == _screen_antialias_cbmi ) {
285 updateOptions( getOptions() );
286 setupScreenTextAntialias( getMainPanel().getTreePanels(), isScreenAntialias() );
288 else if ( o == _background_gradient_cbmi ) {
289 updateOptions( getOptions() );
291 else if ( o == _show_domain_labels ) {
292 updateOptions( getOptions() );
294 else if ( o == _color_labels_same_as_parent_branch ) {
295 updateOptions( getOptions() );
297 else if ( o == _show_default_node_shapes_internal_cbmi ) {
298 updateOptions( getOptions() );
300 else if ( o == _show_default_node_shapes_external_cbmi ) {
301 updateOptions( getOptions() );
303 else if ( o == _taxonomy_colorize_node_shapes_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 ) );
454 Phylogeny[] phys = null;
455 final String tree_url_str = getParameter( Constants.APPLET_PARAM_NAME_FOR_URL_OF_TREE_TO_LOAD );
456 AptxUtil.printAppletMessage( NAME, "URL for phylogenies is " + tree_url_str );
457 // Get URL to tree file
458 if ( tree_url_str != null ) {
460 phys_url = new URL( tree_url_str );
462 catch ( final Exception e ) {
463 ForesterUtil.printErrorMessage( NAME, "error: " + e );
465 JOptionPane.showMessageDialog( this, NAME + ": Could not create URL from: \"" + tree_url_str
466 + "\"\nException: " + e, "Failed to create URL", JOptionPane.ERROR_MESSAGE );
469 // Load the tree from URL
470 if ( phys_url != null ) {
472 phys = AptxUtil.readPhylogeniesFromUrl( phys_url,
473 getConfiguration().isValidatePhyloXmlAgainstSchema(),
474 getConfiguration().isReplaceUnderscoresInNhParsing(),
475 getConfiguration().isInternalNumberAreConfidenceForNhParsing(),
476 getConfiguration().getTaxonomyExtraction(),
477 getConfiguration().isMidpointReroot() );
479 catch ( final Exception e ) {
480 ForesterUtil.printErrorMessage( NAME, e.toString() );
482 JOptionPane.showMessageDialog( this,
483 NAME + ": Failed to read phylogenies: " + "\nException: " + e,
484 "Failed to read phylogenies",
485 JOptionPane.ERROR_MESSAGE );
488 if ( ( phys == null ) || ( phys.length < 1 ) ) {
489 ForesterUtil.printErrorMessage( NAME, "phylogenies from [" + phys_url + "] are null or empty" );
490 JOptionPane.showMessageDialog( this,
491 NAME + ": phylogenies from [" + phys_url + "] are null or empty",
492 "Failed to read phylogenies",
493 JOptionPane.ERROR_MESSAGE );
497 AptxUtil.printAppletMessage( NAME, "loaded " + phys.length + " phylogenies from: " + phys_url );
500 final String species_tree_url_str = getParameter( Constants.APPLET_PARAM_NAME_FOR_URL_OF_SPECIES_TREE_TO_LOAD );
501 if ( !ForesterUtil.isEmpty( species_tree_url_str ) ) {
502 AptxUtil.printAppletMessage( NAME, "URL of species tree to load: \"" + species_tree_url_str + "\"" );
503 Phylogeny[] species_trees = null;
505 final URL species_tree_url = new URL( species_tree_url_str );
506 species_trees = AptxUtil.readPhylogeniesFromUrl( species_tree_url,
507 configuration.isValidatePhyloXmlAgainstSchema(),
508 configuration.isReplaceUnderscoresInNhParsing(),
510 TAXONOMY_EXTRACTION.NO,
513 catch ( final IOException e ) {
514 ForesterUtil.printErrorMessage( NAME, "could not read species tree from [" + species_tree_url_str
516 JOptionPane.showMessageDialog( this, NAME + ": could not read species tree from ["
517 + species_tree_url_str + "]", "Failed to read species tree", JOptionPane.ERROR_MESSAGE );
519 if ( ( species_trees != null ) && ( species_trees.length > 0 ) ) {
520 AptxUtil.printAppletMessage( NAME, "successfully read species tree" );
521 if ( species_trees[ 0 ].isEmpty() ) {
522 ForesterUtil.printErrorMessage( NAME, "species tree is empty" );
524 else if ( !species_trees[ 0 ].isRooted() ) {
525 ForesterUtil.printErrorMessage( NAME, "species tree is not rooted" );
528 setSpeciesTree( species_trees[ 0 ] );
529 AptxUtil.printAppletMessage( NAME, "species tree OK" );
535 setMainPanel( new MainPanelApplets( getConfiguration(), this ) );
536 _jmenubar = new JMenuBar();
537 if ( !getConfiguration().isHideControlPanelAndMenubar() ) {
538 if ( !getConfiguration().isUseNativeUI() ) {
539 _jmenubar.setBackground( getConfiguration().getGuiMenuBackgroundColor() );
541 if ( getSpeciesTree() != null ) {
550 setJMenuBar( _jmenubar );
552 final Container contentpane = getContentPane();
553 contentpane.setLayout( new BorderLayout() );
554 contentpane.add( getMainPanel(), BorderLayout.CENTER );
555 addComponentListener( new ComponentAdapter() {
558 public void componentResized( final ComponentEvent e ) {
559 if ( getMainPanel().getCurrentTreePanel() != null ) {
560 getMainPanel().getCurrentTreePanel().calcParametersForPainting( getMainPanel()
561 .getCurrentTreePanel()
564 .getCurrentTreePanel()
567 .isAllowFontSizeChange() );
571 if ( getConfiguration().isUseTabbedDisplay() ) {
572 AptxUtil.printAppletMessage( NAME, "using tabbed display" );
573 AptxUtil.addPhylogeniesToTabs( phys,
574 new File( phys_url.getFile() ).getName(),
580 AptxUtil.printAppletMessage( NAME, "not using tabbed display" );
581 if ( getSpeciesTree() != null ) {
582 AptxUtil.printAppletMessage( NAME,
583 "Warning: gsdi (gene duplication inference) only available tabbed display" );
585 AptxUtil.addPhylogenyToPanel( phys, getConfiguration(), getMainPanel() );
589 getMainPanel().getControlPanel().showWholeAll();
590 getMainPanel().getControlPanel().showWhole();
592 AptxUtil.printAppletMessage( NAME, "successfully initialized" );
594 getCurrentTreePanel().getControlPanel().getSequenceRelationTypeBox().removeAllItems();
595 for( final SequenceRelation.SEQUENCE_RELATION_TYPE type : getMainPanel().getCurrentPhylogeny()
596 .getRelevantSequenceRelationTypes() ) {
597 getCurrentTreePanel().getControlPanel().getSequenceRelationTypeBox().addItem( type );
599 final String default_relation = getParameter( Constants.APPLET_PARAM_NAME_FOR_DEFAULT_SEQUENCE_RELATION_TYPE );
600 if ( default_relation != null ) {
601 getCurrentTreePanel().getControlPanel().getSequenceRelationTypeBox().setSelectedItem( default_relation );
603 final String default_sequence = getParameter( Constants.APPLET_PARAM_NAME_FOR_DEFAULT_QUERY_SEQUENCE );
604 if ( default_sequence != null ) {
605 getCurrentTreePanel().getControlPanel().getSequenceRelationBox().setSelectedItem( default_sequence );
611 public void showTextFrame( final String s, final String title ) {
613 _textframes.addLast( TextFrame.instantiate( s, title, _textframes ) );
617 public void start() {
618 if ( getMainPanel() != null ) {
619 getMainPanel().validate();
622 requestFocusInWindow();
624 AptxUtil.printAppletMessage( NAME, "started" );
627 void buildAnalysisMenu() {
628 _analysis_menu = MainFrame.createMenu( "Analysis", getConfiguration() );
629 _analysis_menu.add( _gsdi_item = new JMenuItem( "GSDI (Generalized Speciation Duplication Inference)" ) );
630 _analysis_menu.add( _gsdir_item = new JMenuItem( "GSDIR (GSDI with re-rooting)" ) );
631 customizeJMenuItem( _gsdi_item );
632 customizeJMenuItem( _gsdir_item );
633 // _analysis_menu.addSeparator();
634 // _analysis_menu.add( _lineage_inference = new JMenuItem( INFER_ANCESTOR_TAXONOMIES ) );
635 // customizeJMenuItem( _lineage_inference );
636 // _lineage_inference.setToolTipText( "Inference of ancestor taxonomies/lineages" );
637 _jmenubar.add( _analysis_menu );
640 void buildFontSizeMenu() {
641 _font_size_menu = MainFrame.createMenu( MainFrame.FONT_SIZE_MENU_LABEL, getConfiguration() );
642 _font_size_menu.add( _super_tiny_fonts_mi = new JMenuItem( "Super tiny fonts" ) );
643 _font_size_menu.add( _tiny_fonts_mi = new JMenuItem( "Tiny fonts" ) );
644 _font_size_menu.add( _small_fonts_mi = new JMenuItem( "Small fonts" ) );
645 _font_size_menu.add( _medium_fonts_mi = new JMenuItem( "Medium fonts" ) );
646 _font_size_menu.add( _large_fonts_mi = new JMenuItem( "Large fonts" ) );
647 customizeJMenuItem( _super_tiny_fonts_mi );
648 customizeJMenuItem( _tiny_fonts_mi );
649 customizeJMenuItem( _small_fonts_mi );
650 customizeJMenuItem( _medium_fonts_mi );
651 customizeJMenuItem( _large_fonts_mi );
652 _jmenubar.add( _font_size_menu );
655 void buildHelpMenu() {
656 _help_jmenu = MainFrame.createMenu( "Help", getConfiguration() );
657 _help_jmenu.add( _help_item = new JMenuItem( "Help" ) );
658 _help_jmenu.add( _website_item = new JMenuItem( "Archaeopteryx Home" ) );
659 _aptx_ref_item = new JMenuItem( "Archaeopteryx Reference" );
660 _help_jmenu.add( _phyloxml_website_item = new JMenuItem( "phyloXML Home" ) );
661 _help_jmenu.add( _phyloxml_ref_item = new JMenuItem( "phyloXML Reference" ) );
662 _help_jmenu.addSeparator();
663 _help_jmenu.add( _about_item = new JMenuItem( "About" ) );
664 customizeJMenuItem( _help_item );
665 customizeJMenuItem( _website_item );
666 customizeJMenuItem( _phyloxml_website_item );
667 customizeJMenuItem( _aptx_ref_item );
668 customizeJMenuItem( _phyloxml_ref_item );
669 customizeJMenuItem( _about_item );
670 _phyloxml_ref_item.setToolTipText( MainFrame.PHYLOXML_REF_TOOL_TIP );
671 _aptx_ref_item.setToolTipText( MainFrame.APTX_REF_TOOL_TIP );
672 _jmenubar.add( _help_jmenu );
675 void buildOptionsMenu() {
676 _options_jmenu = MainFrame.createMenu( MainFrame.OPTIONS_HEADER, getConfiguration() );
677 _options_jmenu.addChangeListener( new ChangeListener() {
680 public void stateChanged( final ChangeEvent e ) {
681 MainFrame.setOvPlacementColorChooseMenuItem( _overview_placment_mi, getOptions() );
682 MainFrame.setTextColorChooseMenuItem( _switch_colors_mi, getCurrentTreePanel() );
684 .setTextMinSupportMenuItem( _choose_minimal_confidence_mi, getOptions(), getCurrentTreePanel() );
685 MainFrame.setTextForFontChooserMenuItem( _choose_font_mi, MainFrame
686 .createCurrentFontDesc( getMainPanel().getTreeFontSet() ) );
687 MainFrame.updateOptionsMenuDependingOnPhylogenyType( getMainPanel(),
689 _show_branch_length_values_cbmi,
690 _non_lined_up_cladograms_rbmi,
691 _uniform_cladograms_rbmi,
692 _ext_node_dependent_cladogram_rbmi,
693 _label_direction_cbmi );
694 MainFrame.setCycleNodeFillMenuItem( _cycle_node_fill_mi, getOptions() );
695 MainFrame.setCycleNodeShapeMenuItem( _cycle_node_shape_mi, getOptions() );
696 MainFrame.setTextNodeSizeMenuItem( _choose_node_size_mi, getOptions() );
699 _options_jmenu.add( MainFrame.customizeMenuItemAsLabel( new JMenuItem( MainFrame.DISPLAY_SUBHEADER ),
700 getConfiguration() ) );
702 .add( _ext_node_dependent_cladogram_rbmi = new JRadioButtonMenuItem( MainFrame.NONUNIFORM_CLADOGRAMS_LABEL ) );
703 _options_jmenu.add( _uniform_cladograms_rbmi = new JRadioButtonMenuItem( MainFrame.UNIFORM_CLADOGRAMS_LABEL ) );
705 .add( _non_lined_up_cladograms_rbmi = new JRadioButtonMenuItem( MainFrame.NON_LINED_UP_CLADOGRAMS_LABEL ) );
706 _radio_group_1 = new ButtonGroup();
707 _radio_group_1.add( _ext_node_dependent_cladogram_rbmi );
708 _radio_group_1.add( _uniform_cladograms_rbmi );
709 _radio_group_1.add( _non_lined_up_cladograms_rbmi );
711 _options_jmenu.add( _show_overview_cbmi = new JCheckBoxMenuItem( MainFrame.SHOW_OVERVIEW_LABEL ) );
712 _options_jmenu.add( _show_scale_cbmi = new JCheckBoxMenuItem( MainFrame.DISPLAY_SCALE_LABEL ) );
714 .add( _show_branch_length_values_cbmi = new JCheckBoxMenuItem( MainFrame.DISPLAY_BRANCH_LENGTH_VALUES_LABEL ) );
716 .add( _show_default_node_shapes_internal_cbmi = new JCheckBoxMenuItem( MainFrame.DISPLAY_NODE_BOXES_LABEL_INT ) );
718 .add( _show_default_node_shapes_external_cbmi = new JCheckBoxMenuItem( MainFrame.DISPLAY_NODE_BOXES_LABEL_EXT ) );
719 if ( getConfiguration().doDisplayOption( Configuration.show_domain_architectures ) ) {
720 _options_jmenu.add( _show_domain_labels = new JCheckBoxMenuItem( MainFrame.SHOW_DOMAIN_LABELS_LABEL ) );
722 _options_jmenu.add( _show_annotation_ref_source = new JCheckBoxMenuItem( MainFrame.SHOW_ANN_REF_SOURCE_LABEL ) );
723 _options_jmenu.add( _show_confidence_stddev_cbmi = new JCheckBoxMenuItem( MainFrame.SHOW_CONF_STDDEV_LABEL ) );
725 .add( _color_by_taxonomic_group_cbmi = new JCheckBoxMenuItem( MainFrame.COLOR_BY_TAXONOMIC_GROUP ) );
727 .add( _taxonomy_colorize_node_shapes_cbmi = new JCheckBoxMenuItem( MainFrame.TAXONOMY_COLORIZE_NODE_SHAPES_LABEL ) );
729 .add( _color_labels_same_as_parent_branch = new JCheckBoxMenuItem( MainFrame.COLOR_LABELS_LABEL ) );
730 _color_labels_same_as_parent_branch.setToolTipText( MainFrame.COLOR_LABELS_TIP );
731 _options_jmenu.add( _abbreviate_scientific_names = new JCheckBoxMenuItem( MainFrame.ABBREV_SN_LABEL ) );
732 _options_jmenu.add( _label_direction_cbmi = new JCheckBoxMenuItem( MainFrame.LABEL_DIRECTION_LABEL ) );
733 _label_direction_cbmi.setToolTipText( MainFrame.LABEL_DIRECTION_TIP );
734 _options_jmenu.add( _screen_antialias_cbmi = new JCheckBoxMenuItem( MainFrame.SCREEN_ANTIALIAS_LABEL ) );
735 _options_jmenu.add( _background_gradient_cbmi = new JCheckBoxMenuItem( MainFrame.BG_GRAD_LABEL ) );
736 _options_jmenu.add( _cycle_node_shape_mi = new JMenuItem( MainFrame.CYCLE_NODE_SHAPE_LABEL ) );
737 _options_jmenu.add( _cycle_node_fill_mi = new JMenuItem( MainFrame.CYCLE_NODE_FILL_LABEL ) );
738 _options_jmenu.add( _choose_node_size_mi = new JMenuItem( MainFrame.CHOOSE_NODE_SIZE_LABEL ) );
739 _options_jmenu.add( _choose_minimal_confidence_mi = new JMenuItem( "" ) );
740 _options_jmenu.add( _overview_placment_mi = new JMenuItem( "" ) );
741 _options_jmenu.add( _switch_colors_mi = new JMenuItem( "" ) );
742 _options_jmenu.add( _choose_font_mi = new JMenuItem( "" ) );
744 _options_jmenu.addSeparator();
745 _options_jmenu.add( MainFrame.customizeMenuItemAsLabel( new JMenuItem( MainFrame.SEARCH_SUBHEADER ),
746 getConfiguration() ) );
748 .add( _search_case_senstive_cbmi = new JCheckBoxMenuItem( MainFrame.SEARCH_CASE_SENSITIVE_LABEL ) );
749 _options_jmenu.add( _search_whole_words_only_cbmi = new JCheckBoxMenuItem( MainFrame.SEARCH_TERMS_ONLY_LABEL ) );
751 .add( _inverse_search_result_cbmi = new JCheckBoxMenuItem( MainFrame.INVERSE_SEARCH_RESULT_LABEL ) );
752 customizeJMenuItem( _choose_font_mi );
753 customizeJMenuItem( _choose_minimal_confidence_mi );
754 customizeJMenuItem( _switch_colors_mi );
755 customizeJMenuItem( _overview_placment_mi );
756 customizeCheckBoxMenuItem( _color_by_taxonomic_group_cbmi, getOptions().isColorByTaxonomicGroup() );
757 customizeCheckBoxMenuItem( _label_direction_cbmi,
758 getOptions().getNodeLabelDirection() == NODE_LABEL_DIRECTION.RADIAL );
759 customizeCheckBoxMenuItem( _screen_antialias_cbmi, getOptions().isAntialiasScreen() );
760 customizeCheckBoxMenuItem( _background_gradient_cbmi, getOptions().isBackgroundColorGradient() );
761 customizeCheckBoxMenuItem( _show_domain_labels, getOptions().isShowDomainLabels() );
762 customizeCheckBoxMenuItem( _show_annotation_ref_source, getOptions().isShowAnnotationRefSource() );
763 customizeCheckBoxMenuItem( _abbreviate_scientific_names, getOptions().isAbbreviateScientificTaxonNames() );
764 customizeCheckBoxMenuItem( _show_default_node_shapes_external_cbmi, getOptions()
765 .isShowDefaultNodeShapesExternal() );
766 customizeCheckBoxMenuItem( _show_default_node_shapes_internal_cbmi, getOptions()
767 .isShowDefaultNodeShapesInternal() );
768 customizeCheckBoxMenuItem( _taxonomy_colorize_node_shapes_cbmi, getOptions().isTaxonomyColorizeNodeShapes() );
769 customizeJMenuItem( _cycle_node_shape_mi );
770 customizeJMenuItem( _cycle_node_fill_mi );
771 customizeJMenuItem( _choose_node_size_mi );
772 customizeCheckBoxMenuItem( _color_labels_same_as_parent_branch, getOptions().isColorLabelsSameAsParentBranch() );
773 customizeCheckBoxMenuItem( _search_case_senstive_cbmi, getOptions().isSearchCaseSensitive() );
774 customizeCheckBoxMenuItem( _show_scale_cbmi, getOptions().isShowScale() );
775 customizeRadioButtonMenuItem( _non_lined_up_cladograms_rbmi,
776 getOptions().getCladogramType() == CLADOGRAM_TYPE.NON_LINED_UP );
777 customizeRadioButtonMenuItem( _uniform_cladograms_rbmi,
778 getOptions().getCladogramType() == CLADOGRAM_TYPE.TOTAL_NODE_SUM_DEP );
779 customizeRadioButtonMenuItem( _ext_node_dependent_cladogram_rbmi,
780 getOptions().getCladogramType() == CLADOGRAM_TYPE.EXT_NODE_SUM_DEP );
781 customizeCheckBoxMenuItem( _show_branch_length_values_cbmi, getOptions().isShowBranchLengthValues() );
782 customizeCheckBoxMenuItem( _show_overview_cbmi, getOptions().isShowOverview() );
783 customizeCheckBoxMenuItem( _search_whole_words_only_cbmi, getOptions().isMatchWholeTermsOnly() );
784 customizeCheckBoxMenuItem( _inverse_search_result_cbmi, getOptions().isInverseSearchResult() );
785 customizeCheckBoxMenuItem( _show_confidence_stddev_cbmi, getOptions().isShowConfidenceStddev() );
786 _jmenubar.add( _options_jmenu );
789 void buildToolsMenu() {
790 _tools_menu = MainFrame.createMenu( "Tools", getConfiguration() );
791 _tools_menu.add( _confcolor_item = new JMenuItem( "Colorize Branches Depending on Confidence" ) );
792 customizeJMenuItem( _confcolor_item );
793 _tools_menu.add( _taxcolor_item = new JMenuItem( "Taxonomy Colorize Branches" ) );
794 customizeJMenuItem( _taxcolor_item );
795 _tools_menu.add( _remove_branch_color_item = new JMenuItem( "Delete Branch Colors" ) );
796 _remove_branch_color_item.setToolTipText( "To delete branch color values from the current phylogeny." );
797 customizeJMenuItem( _remove_branch_color_item );
798 _tools_menu.addSeparator();
799 _tools_menu.add( _midpoint_root_item = new JMenuItem( "Midpoint-Root" ) );
800 customizeJMenuItem( _midpoint_root_item );
801 _tools_menu.addSeparator();
802 _tools_menu.add( _collapse_species_specific_subtrees = new JMenuItem( "Collapse Species-Specific Subtrees" ) );
803 customizeJMenuItem( _collapse_species_specific_subtrees );
804 _jmenubar.add( _tools_menu );
807 void buildTypeMenu() {
808 _type_menu = MainFrame.createMenu( MainFrame.TYPE_MENU_HEADER, getConfiguration() );
809 _type_menu.add( _rectangular_type_cbmi = new JCheckBoxMenuItem( MainFrame.RECTANGULAR_TYPE_CBMI_LABEL ) );
810 _type_menu.add( _euro_type_cbmi = new JCheckBoxMenuItem( MainFrame.EURO_TYPE_CBMI_LABEL ) );
811 _type_menu.add( _rounded_type_cbmi = new JCheckBoxMenuItem( MainFrame.ROUNDED_TYPE_CBMI_LABEL ) );
812 _type_menu.add( _curved_type_cbmi = new JCheckBoxMenuItem( MainFrame.CURVED_TYPE_CBMI_LABEL ) );
813 _type_menu.add( _triangular_type_cbmi = new JCheckBoxMenuItem( MainFrame.TRIANGULAR_TYPE_CBMI_LABEL ) );
814 _type_menu.add( _convex_type_cbmi = new JCheckBoxMenuItem( MainFrame.CONVEX_TYPE_CBMI_LABEL ) );
815 _type_menu.add( _unrooted_type_cbmi = new JCheckBoxMenuItem( MainFrame.UNROOTED_TYPE_CBMI_LABEL ) );
816 _type_menu.add( _circular_type_cbmi = new JCheckBoxMenuItem( MainFrame.CIRCULAR_TYPE_CBMI_LABEL ) );
817 customizeCheckBoxMenuItem( _rectangular_type_cbmi, false );
818 customizeCheckBoxMenuItem( _triangular_type_cbmi, false );
819 customizeCheckBoxMenuItem( _euro_type_cbmi, false );
820 customizeCheckBoxMenuItem( _rounded_type_cbmi, false );
821 customizeCheckBoxMenuItem( _curved_type_cbmi, false );
822 customizeCheckBoxMenuItem( _convex_type_cbmi, false );
823 customizeCheckBoxMenuItem( _unrooted_type_cbmi, false );
824 customizeCheckBoxMenuItem( _circular_type_cbmi, false );
825 _unrooted_type_cbmi.setToolTipText( MainFrame.USE_MOUSEWHEEL_SHIFT_TO_ROTATE );
826 _circular_type_cbmi.setToolTipText( MainFrame.USE_MOUSEWHEEL_SHIFT_TO_ROTATE );
827 initializeTypeMenu( getOptions() );
828 _jmenubar.add( _type_menu );
831 void buildViewMenu() {
832 _view_jmenu = MainFrame.createMenu( "View", getConfiguration() );
834 .add( _display_basic_information_item = new JMenuItem( MainFrame.SHOW_BASIC_TREE_INFORMATION_LABEL ) );
835 _view_jmenu.addSeparator();
836 _view_jmenu.add( _view_as_XML_item = new JMenuItem( "as phyloXML" ) );
837 _view_jmenu.add( _view_as_NH_item = new JMenuItem( "as Newick" ) );
838 _view_jmenu.add( _view_as_nexus_item = new JMenuItem( "as Nexus" ) );
839 customizeJMenuItem( _display_basic_information_item );
840 customizeJMenuItem( _view_as_NH_item );
841 customizeJMenuItem( _view_as_XML_item );
842 customizeJMenuItem( _view_as_nexus_item );
843 _jmenubar.add( _view_jmenu );
846 void checkTextFrames() {
847 if ( _textframes.size() > 5 ) {
849 if ( _textframes.getFirst() != null ) {
850 _textframes.getFirst().removeMe();
853 _textframes.removeFirst();
856 catch ( final NoSuchElementException e ) {
862 void clearCurrentExternalNodesDataBuffer() {
863 getCurrentTreePanel().clearCurrentExternalNodesDataBuffer();
866 void customizeCheckBoxMenuItem( final JCheckBoxMenuItem item, final boolean is_selected ) {
867 if ( item != null ) {
868 item.setFont( MainFrame.menu_font );
869 if ( !getConfiguration().isUseNativeUI() ) {
870 item.setBackground( getConfiguration().getGuiMenuBackgroundColor() );
871 item.setForeground( getConfiguration().getGuiMenuTextColor() );
873 item.setSelected( is_selected );
874 item.addActionListener( this );
878 void customizeJMenuItem( final JMenuItem jmi ) {
879 jmi.setFont( MainFrame.menu_font );
880 if ( !getConfiguration().isUseNativeUI() ) {
881 jmi.setBackground( getConfiguration().getGuiMenuBackgroundColor() );
882 jmi.setForeground( getConfiguration().getGuiMenuTextColor() );
884 jmi.addActionListener( this );
887 void displayBasicInformation() {
888 if ( ( getMainPanel().getCurrentPhylogeny() != null ) && !getMainPanel().getCurrentPhylogeny().isEmpty() ) {
889 String title = "Basic Information";
890 if ( !ForesterUtil.isEmpty( getMainPanel().getCurrentPhylogeny().getName() ) ) {
891 title = title + " for \"" + _mainpanel.getCurrentPhylogeny().getName() + "\"";
893 showTextFrame( AptxUtil.createBasicInformation( getMainPanel().getCurrentPhylogeny(), null ), title );
898 if ( !isOKforSDI( false, true ) ) {
901 if ( !_mainpanel.getCurrentPhylogeny().isRooted() ) {
902 JOptionPane.showMessageDialog( this,
903 "Gene tree is not rooted.",
904 "Cannot execute GSDI",
905 JOptionPane.ERROR_MESSAGE );
908 final Phylogeny gene_tree = _mainpanel.getCurrentPhylogeny().copy();
909 gene_tree.setAllNodesToNotCollapse();
910 gene_tree.recalculateNumberOfExternalDescendants( false );
912 final Phylogeny species_tree = _species_tree.copy();
914 gsdi = new GSDI( gene_tree, species_tree, false, true, true, true );
916 catch ( final SDIException e ) {
917 JOptionPane.showMessageDialog( this,
918 e.getLocalizedMessage(),
920 JOptionPane.ERROR_MESSAGE );
923 catch ( final Exception e ) {
924 AptxUtil.unexpectedException( e );
927 gene_tree.setRerootable( false );
928 gene_tree.clearHashIdToNodeMap();
929 gene_tree.recalculateNumberOfExternalDescendants( true );
930 _mainpanel.addPhylogenyInNewTab( gene_tree, getConfiguration(), "gene tree", null );
931 getMainPanel().getControlPanel().setShowEvents( true );
933 final int selected = _mainpanel.getTabbedPane().getSelectedIndex();
934 _mainpanel.addPhylogenyInNewTab( species_tree, getConfiguration(), "species tree", null );
936 _mainpanel.getTabbedPane().setSelectedIndex( selected );
938 _mainpanel.getCurrentTreePanel().setEdited( true );
939 final int poly = PhylogenyMethods.countNumberOfPolytomies( species_tree );
940 if ( gsdi.getStrippedExternalGeneTreeNodes().size() > 0 ) {
941 JOptionPane.showMessageDialog( this,
942 "Duplications: " + gsdi.getDuplicationsSum() + "\n"
943 + "Potential duplications: "
944 + gsdi.getSpeciationOrDuplicationEventsSum() + "\n"
945 + "Speciations: " + gsdi.getSpeciationsSum() + "\n"
946 + "Stripped gene tree nodes: "
947 + gsdi.getStrippedExternalGeneTreeNodes().size() + "\n"
948 + "Taxonomy linkage based on: " + gsdi.getTaxCompBase() + "\n"
949 + "Number of polytomies in species tree used: " + poly + "\n",
950 "GSDI successfully completed",
951 JOptionPane.WARNING_MESSAGE );
954 JOptionPane.showMessageDialog( this,
955 "Duplications: " + gsdi.getDuplicationsSum() + "\n"
956 + "Potential duplications: "
957 + gsdi.getSpeciationOrDuplicationEventsSum() + "\n"
958 + "Speciations: " + gsdi.getSpeciationsSum() + "\n"
959 + "Stripped gene tree nodes: "
960 + gsdi.getStrippedExternalGeneTreeNodes().size() + "\n"
961 + "Taxonomy linkage based on: " + gsdi.getTaxCompBase() + "\n"
962 + "Number of polytomies in species tree used: " + poly + "\n",
963 "GSDI successfully completed",
964 JOptionPane.INFORMATION_MESSAGE );
968 void executeGSDIR() {
969 if ( !isOKforSDI( false, false ) ) {
972 final int p = PhylogenyMethods.countNumberOfPolytomies( _mainpanel.getCurrentPhylogeny() );
974 && !( ( p == 1 ) && ( _mainpanel.getCurrentPhylogeny().getRoot().getNumberOfDescendants() == 3 ) ) ) {
975 JOptionPane.showMessageDialog( this,
976 "Gene tree is not completely binary",
977 "Cannot execute GSDI",
978 JOptionPane.ERROR_MESSAGE );
981 final Phylogeny gene_tree = _mainpanel.getCurrentPhylogeny().copy();
982 gene_tree.setAllNodesToNotCollapse();
983 gene_tree.recalculateNumberOfExternalDescendants( false );
985 final Phylogeny species_tree = _species_tree.copy();
987 gsdir = new GSDIR( gene_tree, species_tree, true, true, true );
989 catch ( final SDIException e ) {
990 JOptionPane.showMessageDialog( this,
991 e.getLocalizedMessage(),
992 "Error during GSDIR",
993 JOptionPane.ERROR_MESSAGE );
996 catch ( final Exception e ) {
997 AptxUtil.unexpectedException( e );
1000 final Phylogeny result_gene_tree = gsdir.getMinDuplicationsSumGeneTree();
1001 result_gene_tree.setRerootable( false );
1002 result_gene_tree.clearHashIdToNodeMap();
1003 result_gene_tree.recalculateNumberOfExternalDescendants( true );
1004 PhylogenyMethods.orderAppearance( result_gene_tree.getRoot(), true, true, DESCENDANT_SORT_PRIORITY.NODE_NAME );
1005 _mainpanel.addPhylogenyInNewTab( result_gene_tree, getConfiguration(), "gene tree", null );
1006 getMainPanel().getControlPanel().setShowEvents( true );
1008 final int selected = _mainpanel.getTabbedPane().getSelectedIndex();
1009 _mainpanel.addPhylogenyInNewTab( species_tree, getConfiguration(), "species tree", null );
1011 _mainpanel.getTabbedPane().setSelectedIndex( selected );
1013 _mainpanel.getCurrentTreePanel().setEdited( true );
1014 final int poly = PhylogenyMethods.countNumberOfPolytomies( species_tree );
1015 if ( gsdir.getStrippedExternalGeneTreeNodes().size() > 0 ) {
1016 JOptionPane.showMessageDialog( this,
1017 "Minimal duplications: " + gsdir.getMinDuplicationsSum() + "\n"
1018 + "Speciations: " + gsdir.getSpeciationsSum() + "\n"
1019 + "Stripped gene tree nodes: "
1020 + gsdir.getStrippedExternalGeneTreeNodes().size() + "\n"
1021 + "Taxonomy linkage based on: " + gsdir.getTaxCompBase() + "\n"
1022 + "Number of polytomies in species tree used: " + poly + "\n",
1023 "GSDIR successfully completed",
1024 JOptionPane.WARNING_MESSAGE );
1027 JOptionPane.showMessageDialog( this,
1028 "Minimal duplications: " + gsdir.getMinDuplicationsSum() + "\n"
1029 + "Speciations: " + gsdir.getSpeciationsSum() + "\n"
1030 + "Stripped gene tree nodes: "
1031 + gsdir.getStrippedExternalGeneTreeNodes().size() + "\n"
1032 + "Taxonomy linkage based on: " + gsdir.getTaxCompBase() + "\n"
1033 + "Number of polytomies in species tree used: " + poly + "\n",
1034 "GSDIR successfully completed",
1035 JOptionPane.INFORMATION_MESSAGE );
1039 Configuration getConfiguration() {
1040 return _configuration;
1043 TreePanel getCurrentTreePanel() {
1044 return getMainPanel().getCurrentTreePanel();
1047 JCheckBoxMenuItem getlabelDirectionCbmi() {
1048 return _label_direction_cbmi;
1051 Options getOtions() {
1056 final StringBuilder sb = new StringBuilder();
1057 sb.append( "Display options\n" );
1058 sb.append( "-------------------\n" );
1059 sb.append( "Use the checkboxes to select types of information to display on the tree.\n\n" );
1060 sb.append( "Clickable tree nodes\n" );
1061 sb.append( "--------------------\n" );
1062 sb.append( "Tree nodes can be clicked, the action is determined by the 'click on node to' menu\n" );
1063 sb.append( "or by right clicking:\n" );
1064 sb.append( "o Display Node Data -- display information for a node\n" );
1065 sb.append( "o Collapse/Uncollapse -- collapse and uncollapse subtree from clicked node\n" );
1066 sb.append( "o Root/Reroot -- change tree root to clicked node\n" );
1067 sb.append( "o Sub/Super Tree -- toggle between subtree from clicked node and whole tree\n" );
1068 sb.append( "o Swap Descendants -- switch descendant on either side of clicked node\n" );
1069 sb.append( "o Colorize Subtree -- color a subtree\n" );
1070 sb.append( "o Open Sequence Web -- launch a web browser to display sequence information\n" );
1071 sb.append( "o Open Taxonomy Web -- launch a web browser to display taxonomy information\n" );
1072 sb.append( "- there may be additional choices depending on this particular setup\n\n" );
1073 sb.append( "Right clicking on a node always displays the information of a node.\n\n" );
1074 sb.append( "Zooming\n" );
1075 sb.append( "---------\n" );
1076 sb.append( "The mouse wheel and the plus and minus keys control zooming.\n" );
1077 sb.append( "Mouse wheel+Ctrl changes the text size.\n" );
1078 sb.append( "Mouse wheel+Shift controls zooming in vertical direction only.\n" );
1079 sb.append( "Use the buttons on the control panel to zoom the tree in and out, horizontally or vertically.\n" );
1080 sb.append( "The entire tree can be fitted into the window by clicking the \"F\" button, or by pressing F, Delete, or Home.\n" );
1081 sb.append( "The up, down, left, and right keys can be used to move the visible part (if zoomed in).\n" );
1082 sb.append( "Up, down, left, and right+Shift can be used to control zooming horizontally and vertically.\n" );
1083 sb.append( "Plus and minus keys+Ctrl change the text size; F+Ctrl, Delete+Ctrl, or Home+Ctrl resets it.\n\n" );
1084 sb.append( "Quick tree manipulation:\n" );
1085 sb.append( "------------------------\n" );
1086 sb.append( "Order Subtrees -- order the tree by branch length\n" );
1087 sb.append( "Uncollapse All -- uncollapse any and all collapsed branches\n\n" );
1088 sb.append( "phyloXML\n" );
1089 sb.append( "-------------------\n" );
1090 sb.append( "Reference: " + Constants.PHYLOXML_REFERENCE + "\n" );
1091 sb.append( "Website: " + Constants.PHYLOXML_WEB_SITE + "\n" );
1092 sb.append( "Version: " + ForesterConstants.PHYLO_XML_VERSION + "\n" );
1094 sb.append( "For more information: http://www.phylosoft.org/archaeopteryx/\n" );
1095 sb.append( "Email: " + Constants.AUTHOR_EMAIL + "\n\n" );
1096 TextFrame.instantiate( sb.toString(), "Help", _textframes );
1099 void initializeTypeMenu( final Options options ) {
1100 setTypeMenuToAllUnselected();
1102 switch ( options.getPhylogenyGraphicsType() ) {
1104 _convex_type_cbmi.setSelected( true );
1107 _curved_type_cbmi.setSelected( true );
1110 _euro_type_cbmi.setSelected( true );
1113 _rounded_type_cbmi.setSelected( true );
1116 _triangular_type_cbmi.setSelected( true );
1119 _unrooted_type_cbmi.setSelected( true );
1122 _circular_type_cbmi.setSelected( true );
1125 _rectangular_type_cbmi.setSelected( true );
1129 catch ( final NullPointerException np ) {
1130 // In all likelihood, this is caused by menu-less display.
1134 boolean isOKforSDI( final boolean species_tree_has_to_binary, final boolean gene_tree_has_to_binary ) {
1135 if ( ( _mainpanel.getCurrentPhylogeny() == null ) || _mainpanel.getCurrentPhylogeny().isEmpty() ) {
1138 else if ( ( _species_tree == null ) || _species_tree.isEmpty() ) {
1139 JOptionPane.showMessageDialog( this,
1140 "No species tree loaded",
1141 "Cannot execute GSDI",
1142 JOptionPane.ERROR_MESSAGE );
1145 else if ( species_tree_has_to_binary && !_species_tree.isCompletelyBinary() ) {
1146 JOptionPane.showMessageDialog( this,
1147 "Species tree is not completely binary",
1148 "Cannot execute GSDI",
1149 JOptionPane.ERROR_MESSAGE );
1152 else if ( gene_tree_has_to_binary && !_mainpanel.getCurrentPhylogeny().isCompletelyBinary() ) {
1153 JOptionPane.showMessageDialog( this,
1154 "Gene tree is not completely binary",
1155 "Cannot execute GSDI",
1156 JOptionPane.ERROR_MESSAGE );
1164 boolean isSubtreeDisplayed() {
1165 if ( getCurrentTreePanel() != null ) {
1166 if ( getCurrentTreePanel().isCurrentTreeIsSubtree() ) {
1168 .showMessageDialog( this,
1169 "This operation can only be performed on a complete tree, not on the currently displayed sub-tree only.",
1170 "Operation can not be exectuted on a sub-tree",
1171 JOptionPane.WARNING_MESSAGE );
1178 void removeAllTextFrames() {
1179 for( final TextFrame tf : _textframes ) {
1184 _textframes.clear();
1187 void setConfiguration( final Configuration configuration ) {
1188 _configuration = configuration;
1191 void setOptions( final Options options ) {
1195 void setSelectedTypeInTypeMenu( final PHYLOGENY_GRAPHICS_TYPE type ) {
1196 setTypeMenuToAllUnselected();
1200 _circular_type_cbmi.setSelected( true );
1203 _convex_type_cbmi.setSelected( true );
1206 _curved_type_cbmi.setSelected( true );
1209 _euro_type_cbmi.setSelected( true );
1212 _rounded_type_cbmi.setSelected( true );
1215 _rectangular_type_cbmi.setSelected( true );
1218 _triangular_type_cbmi.setSelected( true );
1221 _unrooted_type_cbmi.setSelected( true );
1224 throw new IllegalArgumentException( "unknown type: " + type );
1227 catch ( final NullPointerException np ) {
1228 // In all likelihood, this is caused by menu-less display.
1232 void setTypeMenuToAllUnselected() {
1233 if ( _convex_type_cbmi != null ) {
1234 _convex_type_cbmi.setSelected( false );
1236 if ( _curved_type_cbmi != null ) {
1237 _curved_type_cbmi.setSelected( false );
1239 if ( _euro_type_cbmi != null ) {
1240 _euro_type_cbmi.setSelected( false );
1242 if ( _rounded_type_cbmi != null ) {
1243 _rounded_type_cbmi.setSelected( false );
1245 if ( _triangular_type_cbmi != null ) {
1246 _triangular_type_cbmi.setSelected( false );
1248 if ( _rectangular_type_cbmi != null ) {
1249 _rectangular_type_cbmi.setSelected( false );
1251 if ( _unrooted_type_cbmi != null ) {
1252 _unrooted_type_cbmi.setSelected( false );
1254 if ( _circular_type_cbmi != null ) {
1255 _circular_type_cbmi.setSelected( false );
1260 _mainpanel.getControlPanel().showWhole();
1263 void switchColors() {
1264 final TreeColorSet colorset = getMainPanel().getCurrentTreePanel().getTreeColorSet();
1265 final ColorSchemeChooser csc = new ColorSchemeChooser( getMainPanel(), colorset );
1266 csc.setVisible( true );
1267 getMainPanel().setTreeColorSet( colorset );
1270 void typeChanged( final Object o ) {
1271 updateTypeCheckboxes( getOptions(), o );
1272 updateOptions( getOptions() );
1273 if ( getCurrentTreePanel() != null ) {
1274 final PHYLOGENY_GRAPHICS_TYPE previous_type = getCurrentTreePanel().getPhylogenyGraphicsType();
1275 final PHYLOGENY_GRAPHICS_TYPE new_type = getOptions().getPhylogenyGraphicsType();
1276 if ( ( ( previous_type == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) && ( new_type != PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) )
1277 || ( ( previous_type == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) && ( new_type != PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) )
1278 || ( ( previous_type != PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) && ( new_type == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) )
1279 || ( ( previous_type != PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) && ( new_type == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) ) ) {
1280 getCurrentTreePanel().getControlPanel().showWhole();
1282 if ( getCurrentTreePanel().isPhyHasBranchLengths() && ( new_type != PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) ) {
1283 getCurrentTreePanel().getControlPanel().setDrawPhylogramEnabled( true );
1286 getCurrentTreePanel().getControlPanel().setDrawPhylogramEnabled( false );
1288 getCurrentTreePanel().setPhylogenyGraphicsType( getOptions().getPhylogenyGraphicsType() );
1289 MainFrame.updateScreenTextAntialias( getMainPanel().getTreePanels() );
1293 void updateOptions( final Options options ) {
1294 options.setAntialiasScreen( ( _screen_antialias_cbmi != null ) && _screen_antialias_cbmi.isSelected() );
1295 options.setBackgroundColorGradient( ( _background_gradient_cbmi != null )
1296 && _background_gradient_cbmi.isSelected() );
1297 options.setShowDomainLabels( ( _show_domain_labels != null ) && _show_domain_labels.isSelected() );
1298 options.setShowAnnotationRefSource( ( _show_annotation_ref_source != null )
1299 && _show_annotation_ref_source.isSelected() );
1300 options.setAbbreviateScientificTaxonNames( ( _abbreviate_scientific_names != null )
1301 && _abbreviate_scientific_names.isSelected() );
1302 options.setColorLabelsSameAsParentBranch( ( _color_labels_same_as_parent_branch != null )
1303 && _color_labels_same_as_parent_branch.isSelected() );
1304 options.setShowDefaultNodeShapesInternal( ( _show_default_node_shapes_internal_cbmi != null )
1305 && _show_default_node_shapes_internal_cbmi.isSelected() );
1306 options.setShowDefaultNodeShapesExternal( ( _show_default_node_shapes_external_cbmi != null )
1307 && _show_default_node_shapes_external_cbmi.isSelected() );
1308 options.setTaxonomyColorizeNodeShapes( ( _taxonomy_colorize_node_shapes_cbmi != null )
1309 && _taxonomy_colorize_node_shapes_cbmi.isSelected() );
1310 if ( ( _non_lined_up_cladograms_rbmi != null ) && ( _non_lined_up_cladograms_rbmi.isSelected() ) ) {
1311 options.setCladogramType( CLADOGRAM_TYPE.NON_LINED_UP );
1313 else if ( ( _uniform_cladograms_rbmi != null ) && ( _uniform_cladograms_rbmi.isSelected() ) ) {
1314 options.setCladogramType( CLADOGRAM_TYPE.TOTAL_NODE_SUM_DEP );
1316 else if ( ( _ext_node_dependent_cladogram_rbmi != null ) && ( _ext_node_dependent_cladogram_rbmi.isSelected() ) ) {
1317 options.setCladogramType( CLADOGRAM_TYPE.EXT_NODE_SUM_DEP );
1319 options.setSearchCaseSensitive( ( _search_case_senstive_cbmi != null )
1320 && _search_case_senstive_cbmi.isSelected() );
1321 if ( ( _show_scale_cbmi != null ) && _show_scale_cbmi.isEnabled() ) {
1322 options.setShowScale( _show_scale_cbmi.isSelected() );
1324 if ( _label_direction_cbmi != null ) {
1325 if ( _label_direction_cbmi.isSelected() ) {
1326 options.setNodeLabelDirection( NODE_LABEL_DIRECTION.RADIAL );
1329 options.setNodeLabelDirection( NODE_LABEL_DIRECTION.HORIZONTAL );
1332 options.setShowOverview( ( _show_overview_cbmi != null ) && _show_overview_cbmi.isSelected() );
1333 options.setShowConfidenceStddev( ( _show_confidence_stddev_cbmi != null )
1334 && _show_confidence_stddev_cbmi.isSelected() );
1335 if ( ( _show_branch_length_values_cbmi != null ) && _show_branch_length_values_cbmi.isEnabled() ) {
1336 options.setShowBranchLengthValues( _show_branch_length_values_cbmi.isSelected() );
1338 options.setMatchWholeTermsOnly( ( _search_whole_words_only_cbmi != null )
1339 && _search_whole_words_only_cbmi.isSelected() );
1340 options.setInverseSearchResult( ( _inverse_search_result_cbmi != null )
1341 && _inverse_search_result_cbmi.isSelected() );
1342 if ( ( _rectangular_type_cbmi != null ) && _rectangular_type_cbmi.isSelected() ) {
1343 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR );
1345 else if ( ( _triangular_type_cbmi != null ) && _triangular_type_cbmi.isSelected() ) {
1346 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.TRIANGULAR );
1348 else if ( ( _curved_type_cbmi != null ) && _curved_type_cbmi.isSelected() ) {
1349 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CURVED );
1351 else if ( ( _convex_type_cbmi != null ) && _convex_type_cbmi.isSelected() ) {
1352 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CONVEX );
1354 else if ( ( _euro_type_cbmi != null ) && _euro_type_cbmi.isSelected() ) {
1355 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE );
1357 else if ( ( _rounded_type_cbmi != null ) && _rounded_type_cbmi.isSelected() ) {
1358 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.ROUNDED );
1360 else if ( ( _unrooted_type_cbmi != null ) && _unrooted_type_cbmi.isSelected() ) {
1361 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.UNROOTED );
1363 else if ( ( _circular_type_cbmi != null ) && _circular_type_cbmi.isSelected() ) {
1364 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CIRCULAR );
1366 if ( ( _color_by_taxonomic_group_cbmi != null ) && _color_by_taxonomic_group_cbmi.isEnabled() ) {
1367 options.setColorByTaxonomicGroup( _color_by_taxonomic_group_cbmi.isSelected() );
1371 void updateTypeCheckboxes( final Options options, final Object o ) {
1372 setTypeMenuToAllUnselected();
1373 ( ( JCheckBoxMenuItem ) o ).setSelected( true );
1376 void viewAsNexus() {
1377 if ( ( getMainPanel().getCurrentPhylogeny() != null ) && !getMainPanel().getCurrentPhylogeny().isEmpty() ) {
1378 String title = "Nexus";
1379 if ( !ForesterUtil.isEmpty( getMainPanel().getCurrentPhylogeny().getName() ) ) {
1380 title = "\"" + getMainPanel().getCurrentPhylogeny().getName() + "\" in " + title;
1382 showTextFrame( getMainPanel().getCurrentPhylogeny().toNexus( getOptions()
1383 .getNhConversionSupportValueStyle() ),
1389 if ( ( getMainPanel().getCurrentPhylogeny() != null ) && !getMainPanel().getCurrentPhylogeny().isEmpty() ) {
1390 String title = "New Hampshire";
1391 if ( !ForesterUtil.isEmpty( getMainPanel().getCurrentPhylogeny().getName() ) ) {
1392 title = "\"" + getMainPanel().getCurrentPhylogeny().getName() + "\" in " + title;
1394 showTextFrame( getMainPanel().getCurrentPhylogeny()
1395 .toNewHampshire( false, getOptions().getNhConversionSupportValueStyle() ),
1401 if ( ( getMainPanel().getCurrentPhylogeny() != null ) && !getMainPanel().getCurrentPhylogeny().isEmpty() ) {
1402 String title = "phyloXML";
1403 if ( !ForesterUtil.isEmpty( getMainPanel().getCurrentPhylogeny().getName() ) ) {
1404 title = "\"" + getMainPanel().getCurrentPhylogeny().getName() + "\" in " + title;
1406 showTextFrame( getMainPanel().getCurrentPhylogeny().toPhyloXML( 0 ), title );
1410 private void chooseFont() {
1411 final FontChooser fc = new FontChooser();
1412 fc.setFont( getMainPanel().getTreeFontSet().getLargeFont() );
1413 fc.showDialog( this, "Select the Base Font" );
1414 getMainPanel().getTreeFontSet().setBaseFont( fc.getFont() );
1417 private void chooseMinimalConfidence() {
1418 final String s = ( String ) JOptionPane
1419 .showInputDialog( this,
1420 "Please the minimum for confidence values to be displayed.\n" + "[current value: "
1421 + getOptions().getMinConfidenceValue() + "]\n",
1422 "Minimal Confidence Value",
1423 JOptionPane.QUESTION_MESSAGE,
1426 getOptions().getMinConfidenceValue() );
1427 if ( !ForesterUtil.isEmpty( s ) ) {
1428 boolean success = true;
1430 final String m_str = s.trim();
1431 if ( !ForesterUtil.isEmpty( m_str ) ) {
1433 m = Double.parseDouble( m_str );
1435 catch ( final Exception ex ) {
1442 if ( success && ( m >= 0.0 ) ) {
1443 getOptions().setMinConfidenceValue( m );
1448 private void customizeRadioButtonMenuItem( final JRadioButtonMenuItem item, final boolean is_selected ) {
1449 if ( item != null ) {
1450 item.setFont( MainFrame.menu_font );
1451 if ( !getConfiguration().isUseNativeUI() ) {
1452 item.setBackground( getConfiguration().getGuiMenuBackgroundColor() );
1453 item.setForeground( getConfiguration().getGuiMenuTextColor() );
1455 item.setSelected( is_selected );
1456 item.addActionListener( this );
1460 private MainPanel getMainPanel() {
1464 private Phylogeny getSpeciesTree() {
1465 return _species_tree;
1468 private boolean isScreenAntialias() {
1472 private void removeBranchColors() {
1473 if ( getMainPanel().getCurrentPhylogeny() != null ) {
1474 AptxUtil.removeBranchColors( getMainPanel().getCurrentPhylogeny() );
1478 private void setMainPanel( final MainPanelApplets main_panel ) {
1479 _mainpanel = main_panel;
1482 private void setSpeciesTree( final Phylogeny species_tree ) {
1483 _species_tree = species_tree;
1486 private void setupUI() {
1488 if ( getConfiguration().isUseNativeUI() ) {
1489 UIManager.setLookAndFeel( UIManager.getSystemLookAndFeelClassName() );
1492 UIManager.setLookAndFeel( UIManager.getCrossPlatformLookAndFeelClassName() );
1495 catch ( final UnsupportedLookAndFeelException e ) {
1496 AptxUtil.dieWithSystemError( "UnsupportedLookAndFeelException: " + e.toString() );
1498 catch ( final ClassNotFoundException e ) {
1499 AptxUtil.dieWithSystemError( "ClassNotFoundException: " + e.toString() );
1501 catch ( final InstantiationException e ) {
1502 AptxUtil.dieWithSystemError( "InstantiationException: " + e.toString() );
1504 catch ( final IllegalAccessException e ) {
1505 AptxUtil.dieWithSystemError( "IllegalAccessException: " + e.toString() );
1507 catch ( final Exception e ) {
1508 AptxUtil.dieWithSystemError( e.toString() );
1512 static void setupScreenTextAntialias( final List<TreePanel> treepanels, final boolean antialias ) {
1513 for( final TreePanel tree_panel : treepanels ) {
1514 tree_panel.setTextAntialias();