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.data.SequenceRelation;
40 import org.forester.sdi.GSDI;
41 import org.forester.sdi.GSDIR;
42 import org.forester.sdi.SDIException;
43 import org.forester.util.ForesterConstants;
44 import org.forester.util.ForesterUtil;
47 // <applet archive="forester.jar"
48 // code="org.forester.archaeopteryx.ArchaeopteryxE.class"
49 // codebase="http://www.myserver.org/path/to/forester"
52 // alt="ArchaeopteryxE is not working on your system (requires at least Sun Java 1.5)!">
53 // <param name="url_of_tree_to_load"
54 // value="http://www.myserver.org/examples/data/apaf.xml">
55 // <param name="config_file"
56 // value="http://www.myserver.org/examples/config/config_file.txt">
58 public class ArchaeopteryxE extends JApplet implements ActionListener {
60 private final static String NAME = "ArchaeopteryxE";
61 private static final long serialVersionUID = -1220055577935759443L;
62 private Configuration _configuration;
63 private MainPanelApplets _mainpanel;
64 private JMenuBar _jmenubar;
65 private JMenu _options_jmenu;
66 private JMenu _font_size_menu;
67 private JMenuItem _super_tiny_fonts_mi;
68 private JMenuItem _tiny_fonts_mi;
69 private JMenuItem _small_fonts_mi;
70 private JMenuItem _medium_fonts_mi;
71 private JMenuItem _large_fonts_mi;
72 private JMenu _tools_menu;
73 private JMenuItem _taxcolor_item;
74 private JMenuItem _confcolor_item;
75 private JMenuItem _midpoint_root_item;
76 private JMenu _view_jmenu;
77 private JMenuItem _view_as_XML_item;
78 private JMenuItem _view_as_NH_item;
79 private JMenuItem _view_as_nexus_item;
80 private JMenuItem _display_basic_information_item;
81 private JMenu _type_menu;
82 private JCheckBoxMenuItem _rectangular_type_cbmi;
83 private JCheckBoxMenuItem _triangular_type_cbmi;
84 private JCheckBoxMenuItem _curved_type_cbmi;
85 private JCheckBoxMenuItem _convex_type_cbmi;
86 private JCheckBoxMenuItem _euro_type_cbmi;
87 private JCheckBoxMenuItem _rounded_type_cbmi;
88 private JCheckBoxMenuItem _unrooted_type_cbmi;
89 private JCheckBoxMenuItem _circular_type_cbmi;
90 private JMenuItem _help_item;
91 private JMenuItem _about_item;
92 private JMenu _help_jmenu;
93 private JMenuItem _website_item;
94 private JMenuItem _phyloxml_website_item;
95 private JMenuItem _phyloxml_ref_item;
96 private JMenuItem _aptx_ref_item;
97 private JMenuItem _remove_branch_color_item;
98 private JCheckBoxMenuItem _show_domain_labels;
99 private JCheckBoxMenuItem _color_labels_same_as_parent_branch;
100 private JCheckBoxMenuItem _abbreviate_scientific_names;
101 private JCheckBoxMenuItem _screen_antialias_cbmi;
102 private JCheckBoxMenuItem _background_gradient_cbmi;
103 private JRadioButtonMenuItem _non_lined_up_cladograms_rbmi;
104 private JRadioButtonMenuItem _uniform_cladograms_rbmi;
105 private JRadioButtonMenuItem _ext_node_dependent_cladogram_rbmi;
106 private Options _options;
107 private JMenuItem _choose_font_mi;
108 private JMenuItem _switch_colors_mi;
109 JCheckBoxMenuItem _label_direction_cbmi;
110 private JCheckBoxMenuItem _show_scale_cbmi;
111 private JCheckBoxMenuItem _search_case_senstive_cbmi;
112 private JCheckBoxMenuItem _search_whole_words_only_cbmi;
113 private JCheckBoxMenuItem _inverse_search_result_cbmi;
114 private JCheckBoxMenuItem _show_overview_cbmi;
115 private JMenuItem _choose_minimal_confidence_mi;
116 private JCheckBoxMenuItem _show_branch_length_values_cbmi;
117 private JMenuItem _collapse_species_specific_subtrees;
118 private JMenuItem _overview_placment_mi;
119 private ButtonGroup _radio_group_1;
120 private JCheckBoxMenuItem _show_default_node_shapes_internal_cbmi;
121 private JCheckBoxMenuItem _show_default_node_shapes_external_cbmi;
122 private JMenuItem _cycle_node_shape_mi;
123 private JMenuItem _cycle_node_fill_mi;
124 private JMenuItem _choose_node_size_mi;
125 private JCheckBoxMenuItem _taxonomy_colorize_node_shapes_cbmi;
126 private JCheckBoxMenuItem _show_confidence_stddev_cbmi;
127 private final LinkedList<TextFrame> _textframes = new LinkedList<TextFrame>();
128 private JMenu _analysis_menu;
129 private JMenuItem _gsdi_item;
130 private JMenuItem _gsdir_item;
131 private Phylogeny _species_tree;
134 public void actionPerformed( final ActionEvent e ) {
135 final Object o = e.getSource();
136 if ( o == _midpoint_root_item ) {
137 getMainPanel().getCurrentTreePanel().midpointRoot();
139 else if ( o == _gsdi_item ) {
140 if ( isSubtreeDisplayed() ) {
145 else if ( o == _gsdir_item ) {
146 if ( isSubtreeDisplayed() ) {
151 else if ( o == _taxcolor_item ) {
152 getMainPanel().getCurrentTreePanel().taxColor();
154 else if ( o == _confcolor_item ) {
155 getMainPanel().getCurrentTreePanel().confColor();
157 else if ( o == _collapse_species_specific_subtrees ) {
158 if ( getCurrentTreePanel() != null ) {
159 getCurrentTreePanel().collapseSpeciesSpecificSubtrees();
162 else if ( o == _remove_branch_color_item ) {
163 removeBranchColors();
165 else if ( o == _switch_colors_mi ) {
168 else if ( o == _display_basic_information_item ) {
169 displayBasicInformation();
171 else if ( o == _view_as_NH_item ) {
174 else if ( o == _view_as_XML_item ) {
177 else if ( o == _view_as_nexus_item ) {
180 else if ( o == _super_tiny_fonts_mi ) {
181 if ( getCurrentTreePanel() != null ) {
182 getCurrentTreePanel().setSuperTinyFonts();
183 getCurrentTreePanel().repaint();
186 else if ( o == _tiny_fonts_mi ) {
187 if ( getCurrentTreePanel() != null ) {
188 getCurrentTreePanel().setTinyFonts();
189 getCurrentTreePanel().repaint();
192 else if ( o == _small_fonts_mi ) {
193 if ( getCurrentTreePanel() != null ) {
194 getCurrentTreePanel().setSmallFonts();
195 getCurrentTreePanel().repaint();
198 else if ( o == _medium_fonts_mi ) {
199 if ( getCurrentTreePanel() != null ) {
200 getCurrentTreePanel().setMediumFonts();
201 getCurrentTreePanel().repaint();
204 else if ( o == _large_fonts_mi ) {
205 if ( getCurrentTreePanel() != null ) {
206 getCurrentTreePanel().setLargeFonts();
207 getCurrentTreePanel().repaint();
210 else if ( o == _choose_font_mi ) {
213 else if ( o == _choose_minimal_confidence_mi ) {
214 chooseMinimalConfidence();
216 else if ( o == _choose_node_size_mi ) {
217 MainFrame.chooseNodeSize( getOptions(), this );
219 else if ( o == _overview_placment_mi ) {
220 MainFrame.cycleOverview( getOptions(), getCurrentTreePanel() );
222 else if ( o == _cycle_node_fill_mi ) {
223 MainFrame.cycleNodeFill( getOptions(), getCurrentTreePanel() );
225 else if ( o == _cycle_node_shape_mi ) {
226 MainFrame.cycleNodeShape( getOptions(), getCurrentTreePanel() );
228 else if ( o == _non_lined_up_cladograms_rbmi ) {
229 updateOptions( getOptions() );
230 _mainpanel.getControlPanel().showWhole();
232 else if ( o == _uniform_cladograms_rbmi ) {
233 updateOptions( getOptions() );
234 _mainpanel.getControlPanel().showWhole();
236 else if ( o == _ext_node_dependent_cladogram_rbmi ) {
237 updateOptions( getOptions() );
238 _mainpanel.getControlPanel().showWhole();
240 else if ( o == _search_case_senstive_cbmi ) {
241 updateOptions( getOptions() );
242 getMainPanel().getControlPanel().search();
244 else if ( o == _search_whole_words_only_cbmi ) {
245 updateOptions( getOptions() );
246 getMainPanel().getControlPanel().search();
248 else if ( o == _inverse_search_result_cbmi ) {
249 updateOptions( getOptions() );
250 getMainPanel().getControlPanel().search();
252 else if ( o == _show_scale_cbmi ) {
253 updateOptions( getOptions() );
255 else if ( o == _show_branch_length_values_cbmi ) {
256 updateOptions( getOptions() );
258 else if ( o == _show_confidence_stddev_cbmi ) {
259 updateOptions( getOptions() );
261 else if ( o == _label_direction_cbmi ) {
262 updateOptions( getOptions() );
264 else if ( o == _show_overview_cbmi ) {
265 updateOptions( getOptions() );
266 if ( getCurrentTreePanel() != null ) {
267 getCurrentTreePanel().updateOvSizes();
270 else if ( ( o == _rectangular_type_cbmi ) || ( o == _triangular_type_cbmi ) || ( o == _curved_type_cbmi )
271 || ( o == _convex_type_cbmi ) || ( o == _rounded_type_cbmi ) || ( o == _euro_type_cbmi )
272 || ( o == _unrooted_type_cbmi ) || ( o == _circular_type_cbmi ) ) {
275 else if ( o == _screen_antialias_cbmi ) {
276 updateOptions( getOptions() );
277 setupScreenTextAntialias( getMainPanel().getTreePanels(), isScreenAntialias() );
279 else if ( o == _background_gradient_cbmi ) {
280 updateOptions( getOptions() );
282 else if ( o == _show_domain_labels ) {
283 updateOptions( getOptions() );
285 else if ( o == _color_labels_same_as_parent_branch ) {
286 updateOptions( getOptions() );
288 else if ( o == _show_default_node_shapes_internal_cbmi ) {
289 updateOptions( getOptions() );
291 else if ( o == _show_default_node_shapes_external_cbmi ) {
292 updateOptions( getOptions() );
294 else if ( o == _taxonomy_colorize_node_shapes_cbmi ) {
295 updateOptions( getOptions() );
297 else if ( o == _about_item ) {
300 else if ( o == _help_item ) {
303 else if ( o == _website_item ) {
305 AptxUtil.openWebsite( Constants.APTX_WEB_SITE, true, this );
307 catch ( final IOException e1 ) {
308 ForesterUtil.printErrorMessage( Constants.PRG_NAME, e1.toString() );
311 else if ( o == _phyloxml_website_item ) {
313 AptxUtil.openWebsite( Constants.PHYLOXML_WEB_SITE, true, this );
315 catch ( final IOException e1 ) {
316 ForesterUtil.printErrorMessage( Constants.PRG_NAME, e1.toString() );
319 else if ( o == _aptx_ref_item ) {
321 AptxUtil.openWebsite( Constants.APTX_REFERENCE_URL, true, this );
323 catch ( final IOException e1 ) {
324 ForesterUtil.printErrorMessage( Constants.PRG_NAME, e1.toString() );
327 else if ( o == _phyloxml_ref_item ) {
329 AptxUtil.openWebsite( Constants.PHYLOXML_REFERENCE_URL, true, this );
331 catch ( final IOException e1 ) {
332 ForesterUtil.printErrorMessage( Constants.PRG_NAME, e1.toString() );
339 public void destroy() {
340 AptxUtil.printAppletMessage( NAME, "going to be destroyed " );
341 removeAllTextFrames();
342 if ( getMainPanel() != null ) {
343 getMainPanel().terminate();
348 * This method returns the current external node data which
349 * has been selected by the user by clicking the "Return ..."
350 * menu item. This method is expected to be called from Javascript or
353 * @return current external node data as String
355 public String getCurrentExternalNodesDataBuffer() {
356 return getCurrentTreePanel().getCurrentExternalNodesDataBufferAsString();
359 public int getCurrentExternalNodesDataBufferChangeCounter() {
360 return getCurrentTreePanel().getCurrentExternalNodesDataBufferChangeCounter();
363 public int getCurrentExternalNodesDataBufferLength() {
364 return getCurrentTreePanel().getCurrentExternalNodesDataBufferAsString().length();
368 * This method returns the current phylogeny as a string in the chosen format
370 * @param format must be NH, NHX, NEXUS or PHYLOXML
371 * @return the phylogeny string
372 * @author Herve Menager
374 public String getCurrentPhylogeny( final String format ) {
375 removeAllTextFrames();
376 if ( ( getMainPanel().getCurrentPhylogeny() == null ) || getMainPanel().getCurrentPhylogeny().isEmpty()
377 || ( getMainPanel().getCurrentPhylogeny().getNumberOfExternalNodes() > 10000 ) ) {
380 switch ( ForesterConstants.PhylogeneticTreeFormats.valueOf( format ) ) {
382 return getMainPanel().getCurrentPhylogeny().toNewHampshire();
384 return getMainPanel().getCurrentPhylogeny().toNewHampshireX();
386 return getMainPanel().getCurrentPhylogeny().toNexus();
388 return getMainPanel().getCurrentPhylogeny().toPhyloXML( -1 );
396 * This method returns a view of the current phylogeny in a chosen
397 * graphics format, base64-encoded in a string so that in can be used
400 * @param format must be GraphicsExportType (gif, jpg, pdf, png, tif, bmp)
401 * @return the phylogeny string
402 * @author Herve Menager
404 public String getCurrentPhylogenyGraphicsAsBase64EncodedString( final String format ) {
405 final ByteArrayOutputStream baos = new ByteArrayOutputStream();
407 AptxUtil.writePhylogenyToGraphicsByteArrayOutputStream( baos,
408 _mainpanel.getWidth(),
409 _mainpanel.getHeight(),
410 getCurrentTreePanel(),
411 getCurrentTreePanel().getControlPanel(),
412 GraphicsExportType.valueOf( format ),
415 catch ( final IOException ioe ) {
416 ForesterUtil.printErrorMessage( NAME, ioe.toString() );
417 ioe.printStackTrace();
418 JOptionPane.showMessageDialog( this,
419 NAME + ": Failed to generate graphics: " + "\nException: " + ioe,
420 "Failed to generate graphics",
421 JOptionPane.ERROR_MESSAGE );
424 final byte[] bytes = baos.toByteArray();
425 final String dataImg = Base64.encodeBase64String( bytes );
429 public Options getOptions() {
435 final String config_filename = getParameter( Constants.APPLET_PARAM_NAME_FOR_CONFIG_FILE_URL );
436 AptxUtil.printAppletMessage( NAME, "URL for configuration file is: " + config_filename );
437 final Configuration configuration = new Configuration( config_filename, true, true, true );
438 setConfiguration( configuration );
439 setOptions( Options.createInstance( configuration ) );
442 Phylogeny[] phys = null;
443 final String tree_url_str = getParameter( Constants.APPLET_PARAM_NAME_FOR_URL_OF_TREE_TO_LOAD );
444 AptxUtil.printAppletMessage( NAME, "URL for phylogenies is " + tree_url_str );
445 // Get URL to tree file
446 if ( tree_url_str != null ) {
448 phys_url = new URL( tree_url_str );
450 catch ( final Exception e ) {
451 ForesterUtil.printErrorMessage( NAME, "error: " + e );
453 JOptionPane.showMessageDialog( this, NAME + ": Could not create URL from: \"" + tree_url_str
454 + "\"\nException: " + e, "Failed to create URL", JOptionPane.ERROR_MESSAGE );
457 // Load the tree from URL
458 if ( phys_url != null ) {
460 phys = AptxUtil.readPhylogeniesFromUrl( phys_url,
461 getConfiguration().isValidatePhyloXmlAgainstSchema(),
462 getConfiguration().isReplaceUnderscoresInNhParsing(),
463 getConfiguration().isInternalNumberAreConfidenceForNhParsing(),
464 getConfiguration().getTaxonomyExtraction(),
465 getConfiguration().isMidpointReroot() );
467 catch ( final Exception e ) {
468 ForesterUtil.printErrorMessage( NAME, e.toString() );
470 JOptionPane.showMessageDialog( this,
471 NAME + ": Failed to read phylogenies: " + "\nException: " + e,
472 "Failed to read phylogenies",
473 JOptionPane.ERROR_MESSAGE );
476 if ( ( phys == null ) || ( phys.length < 1 ) ) {
477 ForesterUtil.printErrorMessage( NAME, "phylogenies from [" + phys_url + "] are null or empty" );
478 JOptionPane.showMessageDialog( this,
479 NAME + ": phylogenies from [" + phys_url + "] are null or empty",
480 "Failed to read phylogenies",
481 JOptionPane.ERROR_MESSAGE );
485 AptxUtil.printAppletMessage( NAME, "loaded " + phys.length + " phylogenies from: " + phys_url );
488 final String species_tree_url_str = getParameter( Constants.APPLET_PARAM_NAME_FOR_URL_OF_SPECIES_TREE_TO_LOAD );
489 if ( !ForesterUtil.isEmpty( species_tree_url_str ) ) {
490 AptxUtil.printAppletMessage( NAME, "URL of species tree to load: \"" + species_tree_url_str + "\"" );
491 Phylogeny[] species_trees = null;
493 final URL species_tree_url = new URL( species_tree_url_str );
494 species_trees = AptxUtil.readPhylogeniesFromUrl( species_tree_url,
495 configuration.isValidatePhyloXmlAgainstSchema(),
496 configuration.isReplaceUnderscoresInNhParsing(),
498 TAXONOMY_EXTRACTION.NO,
501 catch ( final IOException e ) {
502 ForesterUtil.printErrorMessage( NAME, "could not read species tree from [" + species_tree_url_str
504 JOptionPane.showMessageDialog( this, NAME + ": could not read species tree from ["
505 + species_tree_url_str + "]", "Failed to read species tree", JOptionPane.ERROR_MESSAGE );
507 if ( ( species_trees != null ) && ( species_trees.length > 0 ) ) {
508 AptxUtil.printAppletMessage( NAME, "successfully read species tree" );
509 if ( species_trees[ 0 ].isEmpty() ) {
510 ForesterUtil.printErrorMessage( NAME, "species tree is empty" );
512 else if ( !species_trees[ 0 ].isRooted() ) {
513 ForesterUtil.printErrorMessage( NAME, "species tree is not rooted" );
516 setSpeciesTree( species_trees[ 0 ] );
517 AptxUtil.printAppletMessage( NAME, "species tree OK" );
523 setMainPanel( new MainPanelApplets( getConfiguration(), this ) );
524 _jmenubar = new JMenuBar();
525 if ( !getConfiguration().isHideControlPanelAndMenubar() ) {
526 if ( !getConfiguration().isUseNativeUI() ) {
527 _jmenubar.setBackground( getConfiguration().getGuiMenuBackgroundColor() );
529 if ( getSpeciesTree() != null ) {
538 setJMenuBar( _jmenubar );
540 final Container contentpane = getContentPane();
541 contentpane.setLayout( new BorderLayout() );
542 contentpane.add( getMainPanel(), BorderLayout.CENTER );
543 addComponentListener( new ComponentAdapter() {
546 public void componentResized( final ComponentEvent e ) {
547 if ( getMainPanel().getCurrentTreePanel() != null ) {
548 getMainPanel().getCurrentTreePanel().calcParametersForPainting( getMainPanel()
549 .getCurrentTreePanel()
552 .getCurrentTreePanel()
555 .isAllowFontSizeChange() );
559 if ( getConfiguration().isUseTabbedDisplay() ) {
560 AptxUtil.printAppletMessage( NAME, "using tabbed display" );
561 AptxUtil.addPhylogeniesToTabs( phys,
562 new File( phys_url.getFile() ).getName(),
568 AptxUtil.printAppletMessage( NAME, "not using tabbed display" );
569 if ( getSpeciesTree() != null ) {
570 AptxUtil.printAppletMessage( NAME,
571 "Warning: gsdi (gene duplication inference) only available tabbed display" );
573 AptxUtil.addPhylogenyToPanel( phys, getConfiguration(), getMainPanel() );
577 getMainPanel().getControlPanel().showWholeAll();
578 getMainPanel().getControlPanel().showWhole();
580 AptxUtil.printAppletMessage( NAME, "successfully initialized" );
582 getCurrentTreePanel().getControlPanel().getSequenceRelationTypeBox().removeAllItems();
583 for( final SequenceRelation.SEQUENCE_RELATION_TYPE type : getMainPanel().getCurrentPhylogeny()
584 .getRelevantSequenceRelationTypes() ) {
585 getCurrentTreePanel().getControlPanel().getSequenceRelationTypeBox().addItem( type );
587 final String default_relation = getParameter( Constants.APPLET_PARAM_NAME_FOR_DEFAULT_SEQUENCE_RELATION_TYPE );
588 if ( default_relation != null ) {
589 getCurrentTreePanel().getControlPanel().getSequenceRelationTypeBox().setSelectedItem( default_relation );
591 final String default_sequence = getParameter( Constants.APPLET_PARAM_NAME_FOR_DEFAULT_QUERY_SEQUENCE );
592 if ( default_sequence != null ) {
593 getCurrentTreePanel().getControlPanel().getSequenceRelationBox().setSelectedItem( default_sequence );
599 public void showTextFrame( final String s, final String title ) {
601 _textframes.addLast( TextFrame.instantiate( s, title, _textframes ) );
605 public void start() {
606 if ( getMainPanel() != null ) {
607 getMainPanel().validate();
610 requestFocusInWindow();
612 AptxUtil.printAppletMessage( NAME, "started" );
615 void buildAnalysisMenu() {
616 _analysis_menu = MainFrame.createMenu( "Analysis", getConfiguration() );
617 _analysis_menu.add( _gsdi_item = new JMenuItem( "GSDI (Generalized Speciation Duplication Inference)" ) );
618 _analysis_menu.add( _gsdir_item = new JMenuItem( "GSDIR (GSDI with re-rooting)" ) );
619 customizeJMenuItem( _gsdi_item );
620 customizeJMenuItem( _gsdir_item );
621 // _analysis_menu.addSeparator();
622 // _analysis_menu.add( _lineage_inference = new JMenuItem( INFER_ANCESTOR_TAXONOMIES ) );
623 // customizeJMenuItem( _lineage_inference );
624 // _lineage_inference.setToolTipText( "Inference of ancestor taxonomies/lineages" );
625 _jmenubar.add( _analysis_menu );
628 void buildFontSizeMenu() {
629 _font_size_menu = MainFrame.createMenu( MainFrame.FONT_SIZE_MENU_LABEL, getConfiguration() );
630 _font_size_menu.add( _super_tiny_fonts_mi = new JMenuItem( "Super tiny fonts" ) );
631 _font_size_menu.add( _tiny_fonts_mi = new JMenuItem( "Tiny fonts" ) );
632 _font_size_menu.add( _small_fonts_mi = new JMenuItem( "Small fonts" ) );
633 _font_size_menu.add( _medium_fonts_mi = new JMenuItem( "Medium fonts" ) );
634 _font_size_menu.add( _large_fonts_mi = new JMenuItem( "Large fonts" ) );
635 customizeJMenuItem( _super_tiny_fonts_mi );
636 customizeJMenuItem( _tiny_fonts_mi );
637 customizeJMenuItem( _small_fonts_mi );
638 customizeJMenuItem( _medium_fonts_mi );
639 customizeJMenuItem( _large_fonts_mi );
640 _jmenubar.add( _font_size_menu );
643 void buildHelpMenu() {
644 _help_jmenu = MainFrame.createMenu( "Help", getConfiguration() );
645 _help_jmenu.add( _help_item = new JMenuItem( "Help" ) );
646 _help_jmenu.add( _website_item = new JMenuItem( "Archaeopteryx Home" ) );
647 _aptx_ref_item = new JMenuItem( "Archaeopteryx Reference" );
648 _help_jmenu.add( _phyloxml_website_item = new JMenuItem( "phyloXML Home" ) );
649 _help_jmenu.add( _phyloxml_ref_item = new JMenuItem( "phyloXML Reference" ) );
650 _help_jmenu.addSeparator();
651 _help_jmenu.add( _about_item = new JMenuItem( "About" ) );
652 customizeJMenuItem( _help_item );
653 customizeJMenuItem( _website_item );
654 customizeJMenuItem( _phyloxml_website_item );
655 customizeJMenuItem( _aptx_ref_item );
656 customizeJMenuItem( _phyloxml_ref_item );
657 customizeJMenuItem( _about_item );
658 _phyloxml_ref_item.setToolTipText( MainFrame.PHYLOXML_REF_TOOL_TIP );
659 _aptx_ref_item.setToolTipText( MainFrame.APTX_REF_TOOL_TIP );
660 _jmenubar.add( _help_jmenu );
663 void buildOptionsMenu() {
664 _options_jmenu = MainFrame.createMenu( MainFrame.OPTIONS_HEADER, getConfiguration() );
665 _options_jmenu.addChangeListener( new ChangeListener() {
668 public void stateChanged( final ChangeEvent e ) {
669 MainFrame.setOvPlacementColorChooseMenuItem( _overview_placment_mi, getOptions() );
670 MainFrame.setTextColorChooseMenuItem( _switch_colors_mi, getCurrentTreePanel() );
672 .setTextMinSupportMenuItem( _choose_minimal_confidence_mi, getOptions(), getCurrentTreePanel() );
673 MainFrame.setTextForFontChooserMenuItem( _choose_font_mi, MainFrame
674 .createCurrentFontDesc( getMainPanel().getTreeFontSet() ) );
675 MainFrame.updateOptionsMenuDependingOnPhylogenyType( getMainPanel(),
677 _show_branch_length_values_cbmi,
678 _non_lined_up_cladograms_rbmi,
679 _uniform_cladograms_rbmi,
680 _ext_node_dependent_cladogram_rbmi,
681 _label_direction_cbmi );
682 MainFrame.setCycleNodeFillMenuItem( _cycle_node_fill_mi, getOptions() );
683 MainFrame.setCycleNodeShapeMenuItem( _cycle_node_shape_mi, getOptions() );
684 MainFrame.setTextNodeSizeMenuItem( _choose_node_size_mi, getOptions() );
687 _options_jmenu.add( MainFrame.customizeMenuItemAsLabel( new JMenuItem( MainFrame.DISPLAY_SUBHEADER ),
688 getConfiguration() ) );
690 .add( _ext_node_dependent_cladogram_rbmi = new JRadioButtonMenuItem( MainFrame.NONUNIFORM_CLADOGRAMS_LABEL ) );
691 _options_jmenu.add( _uniform_cladograms_rbmi = new JRadioButtonMenuItem( MainFrame.UNIFORM_CLADOGRAMS_LABEL ) );
693 .add( _non_lined_up_cladograms_rbmi = new JRadioButtonMenuItem( MainFrame.NON_LINED_UP_CLADOGRAMS_LABEL ) );
694 _radio_group_1 = new ButtonGroup();
695 _radio_group_1.add( _ext_node_dependent_cladogram_rbmi );
696 _radio_group_1.add( _uniform_cladograms_rbmi );
697 _radio_group_1.add( _non_lined_up_cladograms_rbmi );
698 _options_jmenu.add( _show_overview_cbmi = new JCheckBoxMenuItem( MainFrame.SHOW_OVERVIEW_LABEL ) );
699 _options_jmenu.add( _show_scale_cbmi = new JCheckBoxMenuItem( MainFrame.DISPLAY_SCALE_LABEL ) );
701 .add( _show_branch_length_values_cbmi = new JCheckBoxMenuItem( MainFrame.DISPLAY_BRANCH_LENGTH_VALUES_LABEL ) );
702 _options_jmenu.add( _show_confidence_stddev_cbmi = new JCheckBoxMenuItem( MainFrame.SHOW_CONF_STDDEV_LABEL ) );
704 .add( _show_default_node_shapes_internal_cbmi = new JCheckBoxMenuItem( MainFrame.DISPLAY_NODE_BOXES_LABEL_INT ) );
706 .add( _show_default_node_shapes_external_cbmi = new JCheckBoxMenuItem( MainFrame.DISPLAY_NODE_BOXES_LABEL_EXT ) );
708 .add( _taxonomy_colorize_node_shapes_cbmi = new JCheckBoxMenuItem( MainFrame.TAXONOMY_COLORIZE_NODE_SHAPES_LABEL ) );
709 _options_jmenu.add( _cycle_node_shape_mi = new JMenuItem( MainFrame.CYCLE_NODE_SHAPE_LABEL ) );
710 _options_jmenu.add( _cycle_node_fill_mi = new JMenuItem( MainFrame.CYCLE_NODE_FILL_LABEL ) );
711 _options_jmenu.add( _choose_node_size_mi = new JMenuItem( MainFrame.CHOOSE_NODE_SIZE_LABEL ) );
712 _options_jmenu.add( _label_direction_cbmi = new JCheckBoxMenuItem( MainFrame.LABEL_DIRECTION_LABEL ) );
714 .add( _color_labels_same_as_parent_branch = new JCheckBoxMenuItem( MainFrame.COLOR_LABELS_LABEL ) );
715 _color_labels_same_as_parent_branch.setToolTipText( MainFrame.COLOR_LABELS_TIP );
716 _options_jmenu.add( _abbreviate_scientific_names = new JCheckBoxMenuItem( MainFrame.ABBREV_SN_LABEL ) );
717 _label_direction_cbmi.setToolTipText( MainFrame.LABEL_DIRECTION_TIP );
718 _options_jmenu.add( _screen_antialias_cbmi = new JCheckBoxMenuItem( MainFrame.SCREEN_ANTIALIAS_LABEL ) );
719 _options_jmenu.add( _background_gradient_cbmi = new JCheckBoxMenuItem( MainFrame.BG_GRAD_LABEL ) );
720 if ( getConfiguration().doDisplayOption( Configuration.show_domain_architectures ) ) {
721 _options_jmenu.add( _show_domain_labels = new JCheckBoxMenuItem( MainFrame.SHOW_DOMAIN_LABELS_LABEL ) );
723 _options_jmenu.add( _choose_minimal_confidence_mi = new JMenuItem( "" ) );
724 _options_jmenu.add( _overview_placment_mi = new JMenuItem( "" ) );
725 _options_jmenu.add( _switch_colors_mi = new JMenuItem( "" ) );
726 _options_jmenu.add( _choose_font_mi = new JMenuItem( "" ) );
727 _options_jmenu.addSeparator();
728 _options_jmenu.add( MainFrame.customizeMenuItemAsLabel( new JMenuItem( MainFrame.SEARCH_SUBHEADER ),
729 getConfiguration() ) );
731 .add( _search_case_senstive_cbmi = new JCheckBoxMenuItem( MainFrame.SEARCH_CASE_SENSITIVE_LABEL ) );
732 _options_jmenu.add( _search_whole_words_only_cbmi = new JCheckBoxMenuItem( MainFrame.SEARCH_TERMS_ONLY_LABEL ) );
734 .add( _inverse_search_result_cbmi = new JCheckBoxMenuItem( MainFrame.INVERSE_SEARCH_RESULT_LABEL ) );
735 customizeJMenuItem( _choose_font_mi );
736 customizeJMenuItem( _choose_minimal_confidence_mi );
737 customizeJMenuItem( _switch_colors_mi );
738 customizeJMenuItem( _overview_placment_mi );
739 customizeCheckBoxMenuItem( _label_direction_cbmi,
740 getOptions().getNodeLabelDirection() == NODE_LABEL_DIRECTION.RADIAL );
741 customizeCheckBoxMenuItem( _screen_antialias_cbmi, getOptions().isAntialiasScreen() );
742 customizeCheckBoxMenuItem( _background_gradient_cbmi, getOptions().isBackgroundColorGradient() );
743 customizeCheckBoxMenuItem( _show_domain_labels, getOptions().isShowDomainLabels() );
744 customizeCheckBoxMenuItem( _abbreviate_scientific_names, getOptions().isAbbreviateScientificTaxonNames() );
745 customizeCheckBoxMenuItem( _show_default_node_shapes_external_cbmi, getOptions()
746 .isShowDefaultNodeShapesExternal() );
747 customizeCheckBoxMenuItem( _show_default_node_shapes_internal_cbmi, getOptions()
748 .isShowDefaultNodeShapesInternal() );
749 customizeCheckBoxMenuItem( _taxonomy_colorize_node_shapes_cbmi, getOptions().isTaxonomyColorizeNodeShapes() );
750 customizeJMenuItem( _cycle_node_shape_mi );
751 customizeJMenuItem( _cycle_node_fill_mi );
752 customizeJMenuItem( _choose_node_size_mi );
753 customizeCheckBoxMenuItem( _color_labels_same_as_parent_branch, getOptions().isColorLabelsSameAsParentBranch() );
754 customizeCheckBoxMenuItem( _search_case_senstive_cbmi, getOptions().isSearchCaseSensitive() );
755 customizeCheckBoxMenuItem( _show_scale_cbmi, getOptions().isShowScale() );
756 customizeRadioButtonMenuItem( _non_lined_up_cladograms_rbmi,
757 getOptions().getCladogramType() == CLADOGRAM_TYPE.NON_LINED_UP );
758 customizeRadioButtonMenuItem( _uniform_cladograms_rbmi,
759 getOptions().getCladogramType() == CLADOGRAM_TYPE.TOTAL_NODE_SUM_DEP );
760 customizeRadioButtonMenuItem( _ext_node_dependent_cladogram_rbmi,
761 getOptions().getCladogramType() == CLADOGRAM_TYPE.EXT_NODE_SUM_DEP );
762 customizeCheckBoxMenuItem( _show_branch_length_values_cbmi, getOptions().isShowBranchLengthValues() );
763 customizeCheckBoxMenuItem( _show_overview_cbmi, getOptions().isShowOverview() );
764 customizeCheckBoxMenuItem( _search_whole_words_only_cbmi, getOptions().isMatchWholeTermsOnly() );
765 customizeCheckBoxMenuItem( _inverse_search_result_cbmi, getOptions().isInverseSearchResult() );
766 customizeCheckBoxMenuItem( _show_confidence_stddev_cbmi, getOptions().isShowConfidenceStddev() );
767 _jmenubar.add( _options_jmenu );
770 void buildToolsMenu() {
771 _tools_menu = MainFrame.createMenu( "Tools", getConfiguration() );
772 _tools_menu.add( _confcolor_item = new JMenuItem( "Colorize Branches Depending on Confidence" ) );
773 customizeJMenuItem( _confcolor_item );
774 _tools_menu.add( _taxcolor_item = new JMenuItem( "Taxonomy Colorize Branches" ) );
775 customizeJMenuItem( _taxcolor_item );
776 _tools_menu.add( _remove_branch_color_item = new JMenuItem( "Delete Branch Colors" ) );
777 _remove_branch_color_item.setToolTipText( "To delete branch color values from the current phylogeny." );
778 customizeJMenuItem( _remove_branch_color_item );
779 _tools_menu.addSeparator();
780 _tools_menu.add( _midpoint_root_item = new JMenuItem( "Midpoint-Root" ) );
781 customizeJMenuItem( _midpoint_root_item );
782 _tools_menu.addSeparator();
783 _tools_menu.add( _collapse_species_specific_subtrees = new JMenuItem( "Collapse Species-Specific Subtrees" ) );
784 customizeJMenuItem( _collapse_species_specific_subtrees );
785 _jmenubar.add( _tools_menu );
788 void buildTypeMenu() {
789 _type_menu = MainFrame.createMenu( MainFrame.TYPE_MENU_HEADER, getConfiguration() );
790 _type_menu.add( _rectangular_type_cbmi = new JCheckBoxMenuItem( MainFrame.RECTANGULAR_TYPE_CBMI_LABEL ) );
791 _type_menu.add( _euro_type_cbmi = new JCheckBoxMenuItem( MainFrame.EURO_TYPE_CBMI_LABEL ) );
792 _type_menu.add( _rounded_type_cbmi = new JCheckBoxMenuItem( MainFrame.ROUNDED_TYPE_CBMI_LABEL ) );
793 _type_menu.add( _curved_type_cbmi = new JCheckBoxMenuItem( MainFrame.CURVED_TYPE_CBMI_LABEL ) );
794 _type_menu.add( _triangular_type_cbmi = new JCheckBoxMenuItem( MainFrame.TRIANGULAR_TYPE_CBMI_LABEL ) );
795 _type_menu.add( _convex_type_cbmi = new JCheckBoxMenuItem( MainFrame.CONVEX_TYPE_CBMI_LABEL ) );
796 _type_menu.add( _unrooted_type_cbmi = new JCheckBoxMenuItem( MainFrame.UNROOTED_TYPE_CBMI_LABEL ) );
797 _type_menu.add( _circular_type_cbmi = new JCheckBoxMenuItem( MainFrame.CIRCULAR_TYPE_CBMI_LABEL ) );
798 customizeCheckBoxMenuItem( _rectangular_type_cbmi, false );
799 customizeCheckBoxMenuItem( _triangular_type_cbmi, false );
800 customizeCheckBoxMenuItem( _euro_type_cbmi, false );
801 customizeCheckBoxMenuItem( _rounded_type_cbmi, false );
802 customizeCheckBoxMenuItem( _curved_type_cbmi, false );
803 customizeCheckBoxMenuItem( _convex_type_cbmi, false );
804 customizeCheckBoxMenuItem( _unrooted_type_cbmi, false );
805 customizeCheckBoxMenuItem( _circular_type_cbmi, false );
806 _unrooted_type_cbmi.setToolTipText( MainFrame.USE_MOUSEWHEEL_SHIFT_TO_ROTATE );
807 _circular_type_cbmi.setToolTipText( MainFrame.USE_MOUSEWHEEL_SHIFT_TO_ROTATE );
808 initializeTypeMenu( getOptions() );
809 _jmenubar.add( _type_menu );
812 void buildViewMenu() {
813 _view_jmenu = MainFrame.createMenu( "View", getConfiguration() );
814 _view_jmenu.add( _display_basic_information_item = new JMenuItem( "Display Basic Information" ) );
815 _view_jmenu.addSeparator();
816 _view_jmenu.add( _view_as_XML_item = new JMenuItem( "View as phyloXML" ) );
817 _view_jmenu.add( _view_as_NH_item = new JMenuItem( "View as Newick" ) );
818 _view_jmenu.add( _view_as_nexus_item = new JMenuItem( "View as Nexus" ) );
819 customizeJMenuItem( _display_basic_information_item );
820 customizeJMenuItem( _view_as_NH_item );
821 customizeJMenuItem( _view_as_XML_item );
822 customizeJMenuItem( _view_as_nexus_item );
823 _jmenubar.add( _view_jmenu );
826 void checkTextFrames() {
827 if ( _textframes.size() > 5 ) {
829 if ( _textframes.getFirst() != null ) {
830 _textframes.getFirst().removeMe();
833 _textframes.removeFirst();
836 catch ( final NoSuchElementException e ) {
842 void clearCurrentExternalNodesDataBuffer() {
843 getCurrentTreePanel().clearCurrentExternalNodesDataBuffer();
846 void customizeCheckBoxMenuItem( final JCheckBoxMenuItem item, final boolean is_selected ) {
847 if ( item != null ) {
848 item.setFont( MainFrame.menu_font );
849 if ( !getConfiguration().isUseNativeUI() ) {
850 item.setBackground( getConfiguration().getGuiMenuBackgroundColor() );
851 item.setForeground( getConfiguration().getGuiMenuTextColor() );
853 item.setSelected( is_selected );
854 item.addActionListener( this );
858 void customizeJMenuItem( final JMenuItem jmi ) {
859 jmi.setFont( MainFrame.menu_font );
860 if ( !getConfiguration().isUseNativeUI() ) {
861 jmi.setBackground( getConfiguration().getGuiMenuBackgroundColor() );
862 jmi.setForeground( getConfiguration().getGuiMenuTextColor() );
864 jmi.addActionListener( this );
867 void displayBasicInformation() {
868 if ( ( getMainPanel().getCurrentPhylogeny() != null ) && !getMainPanel().getCurrentPhylogeny().isEmpty() ) {
869 String title = "Basic Information";
870 if ( !ForesterUtil.isEmpty( getMainPanel().getCurrentPhylogeny().getName() ) ) {
871 title = getMainPanel().getCurrentPhylogeny().getName() + " " + title;
873 showTextFrame( AptxUtil.createBasicInformation( getMainPanel().getCurrentPhylogeny() ), title );
878 if ( !isOKforSDI( false, true ) ) {
881 if ( !_mainpanel.getCurrentPhylogeny().isRooted() ) {
882 JOptionPane.showMessageDialog( this,
883 "Gene tree is not rooted.",
884 "Cannot execute GSDI",
885 JOptionPane.ERROR_MESSAGE );
888 final Phylogeny gene_tree = _mainpanel.getCurrentPhylogeny().copy();
889 gene_tree.setAllNodesToNotCollapse();
890 gene_tree.recalculateNumberOfExternalDescendants( false );
892 final Phylogeny species_tree = _species_tree.copy();
894 gsdi = new GSDI( gene_tree, species_tree, false, true, true );
896 catch ( final SDIException e ) {
897 JOptionPane.showMessageDialog( this,
898 e.getLocalizedMessage(),
900 JOptionPane.ERROR_MESSAGE );
903 catch ( final Exception e ) {
904 AptxUtil.unexpectedException( e );
907 gene_tree.setRerootable( false );
908 gene_tree.clearHashIdToNodeMap();
909 gene_tree.recalculateNumberOfExternalDescendants( true );
910 _mainpanel.addPhylogenyInNewTab( gene_tree, getConfiguration(), "gene tree", null );
911 getMainPanel().getControlPanel().setShowEvents( true );
913 final int selected = _mainpanel.getTabbedPane().getSelectedIndex();
914 _mainpanel.addPhylogenyInNewTab( species_tree, getConfiguration(), "species tree", null );
916 _mainpanel.getTabbedPane().setSelectedIndex( selected );
918 _mainpanel.getCurrentTreePanel().setEdited( true );
919 final int poly = PhylogenyMethods.countNumberOfPolytomies( species_tree );
920 if ( gsdi.getStrippedExternalGeneTreeNodes().size() > 0 ) {
921 JOptionPane.showMessageDialog( this,
922 "Duplications: " + gsdi.getDuplicationsSum() + "\n"
923 + "Potential duplications: "
924 + gsdi.getSpeciationOrDuplicationEventsSum() + "\n"
925 + "Speciations: " + gsdi.getSpeciationsSum() + "\n"
926 + "Stripped gene tree nodes: "
927 + gsdi.getStrippedExternalGeneTreeNodes().size() + "\n"
928 + "Taxonomy linkage based on: " + gsdi.getTaxCompBase() + "\n"
929 + "Number of polytomies in species tree used: " + poly + "\n",
930 "GSDI successfully completed",
931 JOptionPane.WARNING_MESSAGE );
934 JOptionPane.showMessageDialog( this,
935 "Duplications: " + gsdi.getDuplicationsSum() + "\n"
936 + "Potential duplications: "
937 + gsdi.getSpeciationOrDuplicationEventsSum() + "\n"
938 + "Speciations: " + gsdi.getSpeciationsSum() + "\n"
939 + "Stripped gene tree nodes: "
940 + gsdi.getStrippedExternalGeneTreeNodes().size() + "\n"
941 + "Taxonomy linkage based on: " + gsdi.getTaxCompBase() + "\n"
942 + "Number of polytomies in species tree used: " + poly + "\n",
943 "GSDI successfully completed",
944 JOptionPane.INFORMATION_MESSAGE );
948 void executeGSDIR() {
949 if ( !isOKforSDI( false, false ) ) {
952 final int p = PhylogenyMethods.countNumberOfPolytomies( _mainpanel.getCurrentPhylogeny() );
954 && !( ( p == 1 ) && ( _mainpanel.getCurrentPhylogeny().getRoot().getNumberOfDescendants() == 3 ) ) ) {
955 JOptionPane.showMessageDialog( this,
956 "Gene tree is not completely binary",
957 "Cannot execute GSDI",
958 JOptionPane.ERROR_MESSAGE );
961 final Phylogeny gene_tree = _mainpanel.getCurrentPhylogeny().copy();
962 gene_tree.setAllNodesToNotCollapse();
963 gene_tree.recalculateNumberOfExternalDescendants( false );
965 final Phylogeny species_tree = _species_tree.copy();
967 gsdir = new GSDIR( gene_tree, species_tree, true, true );
969 catch ( final SDIException e ) {
970 JOptionPane.showMessageDialog( this,
971 e.getLocalizedMessage(),
972 "Error during GSDIR",
973 JOptionPane.ERROR_MESSAGE );
976 catch ( final Exception e ) {
977 AptxUtil.unexpectedException( e );
980 final Phylogeny result_gene_tree = gsdir.getMinDuplicationsSumGeneTree();
981 result_gene_tree.setRerootable( false );
982 result_gene_tree.clearHashIdToNodeMap();
983 result_gene_tree.recalculateNumberOfExternalDescendants( true );
984 _mainpanel.addPhylogenyInNewTab( result_gene_tree, getConfiguration(), "gene tree", null );
985 getMainPanel().getControlPanel().setShowEvents( true );
987 final int selected = _mainpanel.getTabbedPane().getSelectedIndex();
988 _mainpanel.addPhylogenyInNewTab( species_tree, getConfiguration(), "species tree", null );
990 _mainpanel.getTabbedPane().setSelectedIndex( selected );
992 _mainpanel.getCurrentTreePanel().setEdited( true );
993 final int poly = PhylogenyMethods.countNumberOfPolytomies( species_tree );
994 if ( gsdir.getStrippedExternalGeneTreeNodes().size() > 0 ) {
995 JOptionPane.showMessageDialog( this,
996 "Minimal duplications: " + gsdir.getMinDuplicationsSum() + "\n"
997 + "Speciations: " + gsdir.getSpeciationsSum() + "\n"
998 + "Stripped gene tree nodes: "
999 + gsdir.getStrippedExternalGeneTreeNodes().size() + "\n"
1000 + "Taxonomy linkage based on: " + gsdir.getTaxCompBase() + "\n"
1001 + "Number of polytomies in species tree used: " + poly + "\n",
1002 "GSDIR successfully completed",
1003 JOptionPane.WARNING_MESSAGE );
1006 JOptionPane.showMessageDialog( this,
1007 "Minimal duplications: " + gsdir.getMinDuplicationsSum() + "\n"
1008 + "Speciations: " + gsdir.getSpeciationsSum() + "\n"
1009 + "Stripped gene tree nodes: "
1010 + gsdir.getStrippedExternalGeneTreeNodes().size() + "\n"
1011 + "Taxonomy linkage based on: " + gsdir.getTaxCompBase() + "\n"
1012 + "Number of polytomies in species tree used: " + poly + "\n",
1013 "GSDIR successfully completed",
1014 JOptionPane.INFORMATION_MESSAGE );
1018 Configuration getConfiguration() {
1019 return _configuration;
1022 TreePanel getCurrentTreePanel() {
1023 return getMainPanel().getCurrentTreePanel();
1026 JCheckBoxMenuItem getlabelDirectionCbmi() {
1027 return _label_direction_cbmi;
1030 Options getOtions() {
1035 final StringBuilder sb = new StringBuilder();
1036 sb.append( "Display options\n" );
1037 sb.append( "-------------------\n" );
1038 sb.append( "Use the checkboxes to select types of information to display on the tree.\n\n" );
1039 sb.append( "Clickable tree nodes\n" );
1040 sb.append( "--------------------\n" );
1041 sb.append( "Tree nodes can be clicked, the action is determined by the 'click on node to' menu\n" );
1042 sb.append( "or by right clicking:\n" );
1043 sb.append( "o Display Node Data -- display information for a node\n" );
1044 sb.append( "o Collapse/Uncollapse -- collapse and uncollapse subtree from clicked node\n" );
1045 sb.append( "o Root/Reroot -- change tree root to clicked node\n" );
1046 sb.append( "o Sub/Super Tree -- toggle between subtree from clicked node and whole tree\n" );
1047 sb.append( "o Swap Descendants -- switch descendant on either side of clicked node\n" );
1048 sb.append( "o Colorize Subtree -- color a subtree\n" );
1049 sb.append( "o Open Sequence Web -- launch a web browser to display sequence information\n" );
1050 sb.append( "o Open Taxonomy Web -- launch a web browser to display taxonomy information\n" );
1051 sb.append( "- there may be additional choices depending on this particular setup\n\n" );
1052 sb.append( "Right clicking on a node always displays the information of a node.\n\n" );
1053 sb.append( "Zooming\n" );
1054 sb.append( "---------\n" );
1055 sb.append( "The mouse wheel and the plus and minus keys control zooming.\n" );
1056 sb.append( "Mouse wheel+Ctrl changes the text size.\n" );
1057 sb.append( "Mouse wheel+Shift controls zooming in vertical direction only.\n" );
1058 sb.append( "Use the buttons on the control panel to zoom the tree in and out, horizontally or vertically.\n" );
1059 sb.append( "The entire tree can be fitted into the window by clicking the \"F\" button, or by pressing F, Delete, or Home.\n" );
1060 sb.append( "The up, down, left, and right keys can be used to move the visible part (if zoomed in).\n" );
1061 sb.append( "Up, down, left, and right+Shift can be used to control zooming horizontally and vertically.\n" );
1062 sb.append( "Plus and minus keys+Ctrl change the text size; F+Ctrl, Delete+Ctrl, or Home+Ctrl resets it.\n\n" );
1063 sb.append( "Quick tree manipulation:\n" );
1064 sb.append( "------------------------\n" );
1065 sb.append( "Order Subtrees -- order the tree by branch length\n" );
1066 sb.append( "Uncollapse All -- uncollapse any and all collapsed branches\n\n" );
1067 sb.append( "phyloXML\n" );
1068 sb.append( "-------------------\n" );
1069 sb.append( "Reference: " + Constants.PHYLOXML_REFERENCE + "\n" );
1070 sb.append( "Website: " + Constants.PHYLOXML_WEB_SITE + "\n" );
1071 sb.append( "Version: " + ForesterConstants.PHYLO_XML_VERSION + "\n" );
1073 sb.append( "For more information: http://www.phylosoft.org/archaeopteryx/\n" );
1074 sb.append( "Email: " + Constants.AUTHOR_EMAIL + "\n\n" );
1075 TextFrame.instantiate( sb.toString(), "Help", _textframes );
1078 void initializeTypeMenu( final Options options ) {
1079 setTypeMenuToAllUnselected();
1081 switch ( options.getPhylogenyGraphicsType() ) {
1083 _convex_type_cbmi.setSelected( true );
1086 _curved_type_cbmi.setSelected( true );
1089 _euro_type_cbmi.setSelected( true );
1092 _rounded_type_cbmi.setSelected( true );
1095 _triangular_type_cbmi.setSelected( true );
1098 _unrooted_type_cbmi.setSelected( true );
1101 _circular_type_cbmi.setSelected( true );
1104 _rectangular_type_cbmi.setSelected( true );
1108 catch ( final NullPointerException np ) {
1109 // In all likelihood, this is caused by menu-less display.
1113 boolean isOKforSDI( final boolean species_tree_has_to_binary, final boolean gene_tree_has_to_binary ) {
1114 if ( ( _mainpanel.getCurrentPhylogeny() == null ) || _mainpanel.getCurrentPhylogeny().isEmpty() ) {
1117 else if ( ( _species_tree == null ) || _species_tree.isEmpty() ) {
1118 JOptionPane.showMessageDialog( this,
1119 "No species tree loaded",
1120 "Cannot execute GSDI",
1121 JOptionPane.ERROR_MESSAGE );
1124 else if ( species_tree_has_to_binary && !_species_tree.isCompletelyBinary() ) {
1125 JOptionPane.showMessageDialog( this,
1126 "Species tree is not completely binary",
1127 "Cannot execute GSDI",
1128 JOptionPane.ERROR_MESSAGE );
1131 else if ( gene_tree_has_to_binary && !_mainpanel.getCurrentPhylogeny().isCompletelyBinary() ) {
1132 JOptionPane.showMessageDialog( this,
1133 "Gene tree is not completely binary",
1134 "Cannot execute GSDI",
1135 JOptionPane.ERROR_MESSAGE );
1143 boolean isSubtreeDisplayed() {
1144 if ( getCurrentTreePanel() != null ) {
1145 if ( getCurrentTreePanel().isCurrentTreeIsSubtree() ) {
1147 .showMessageDialog( this,
1148 "This operation can only be performed on a complete tree, not on the currently displayed sub-tree only.",
1149 "Operation can not be exectuted on a sub-tree",
1150 JOptionPane.WARNING_MESSAGE );
1157 void removeAllTextFrames() {
1158 for( final TextFrame tf : _textframes ) {
1163 _textframes.clear();
1166 void setConfiguration( final Configuration configuration ) {
1167 _configuration = configuration;
1170 void setOptions( final Options options ) {
1174 void setSelectedTypeInTypeMenu( final PHYLOGENY_GRAPHICS_TYPE type ) {
1175 setTypeMenuToAllUnselected();
1179 _circular_type_cbmi.setSelected( true );
1182 _convex_type_cbmi.setSelected( true );
1185 _curved_type_cbmi.setSelected( true );
1188 _euro_type_cbmi.setSelected( true );
1191 _rounded_type_cbmi.setSelected( true );
1194 _rectangular_type_cbmi.setSelected( true );
1197 _triangular_type_cbmi.setSelected( true );
1200 _unrooted_type_cbmi.setSelected( true );
1203 throw new IllegalArgumentException( "unknown type: " + type );
1206 catch ( final NullPointerException np ) {
1207 // In all likelihood, this is caused by menu-less display.
1211 void setTypeMenuToAllUnselected() {
1212 if ( _convex_type_cbmi != null ) {
1213 _convex_type_cbmi.setSelected( false );
1215 if ( _curved_type_cbmi != null ) {
1216 _curved_type_cbmi.setSelected( false );
1218 if ( _euro_type_cbmi != null ) {
1219 _euro_type_cbmi.setSelected( false );
1221 if ( _rounded_type_cbmi != null ) {
1222 _rounded_type_cbmi.setSelected( false );
1224 if ( _triangular_type_cbmi != null ) {
1225 _triangular_type_cbmi.setSelected( false );
1227 if ( _rectangular_type_cbmi != null ) {
1228 _rectangular_type_cbmi.setSelected( false );
1230 if ( _unrooted_type_cbmi != null ) {
1231 _unrooted_type_cbmi.setSelected( false );
1233 if ( _circular_type_cbmi != null ) {
1234 _circular_type_cbmi.setSelected( false );
1239 _mainpanel.getControlPanel().showWhole();
1242 void switchColors() {
1243 final TreeColorSet colorset = getMainPanel().getCurrentTreePanel().getTreeColorSet();
1244 final ColorSchemeChooser csc = new ColorSchemeChooser( getMainPanel(), colorset );
1245 csc.setVisible( true );
1246 getMainPanel().setTreeColorSet( colorset );
1249 void typeChanged( final Object o ) {
1250 updateTypeCheckboxes( getOptions(), o );
1251 updateOptions( getOptions() );
1252 if ( getCurrentTreePanel() != null ) {
1253 final PHYLOGENY_GRAPHICS_TYPE previous_type = getCurrentTreePanel().getPhylogenyGraphicsType();
1254 final PHYLOGENY_GRAPHICS_TYPE new_type = getOptions().getPhylogenyGraphicsType();
1255 if ( ( ( previous_type == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) && ( new_type != PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) )
1256 || ( ( previous_type == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) && ( new_type != PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) )
1257 || ( ( previous_type != PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) && ( new_type == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) )
1258 || ( ( previous_type != PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) && ( new_type == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) ) ) {
1259 getCurrentTreePanel().getControlPanel().showWhole();
1261 if ( getCurrentTreePanel().isPhyHasBranchLengths() && ( new_type != PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) ) {
1262 getCurrentTreePanel().getControlPanel().setDrawPhylogramEnabled( true );
1265 getCurrentTreePanel().getControlPanel().setDrawPhylogramEnabled( false );
1267 getCurrentTreePanel().setPhylogenyGraphicsType( getOptions().getPhylogenyGraphicsType() );
1268 MainFrame.updateScreenTextAntialias( getMainPanel().getTreePanels() );
1272 void updateOptions( final Options options ) {
1273 options.setAntialiasScreen( ( _screen_antialias_cbmi != null ) && _screen_antialias_cbmi.isSelected() );
1274 options.setBackgroundColorGradient( ( _background_gradient_cbmi != null )
1275 && _background_gradient_cbmi.isSelected() );
1276 options.setShowDomainLabels( ( _show_domain_labels != null ) && _show_domain_labels.isSelected() );
1277 options.setAbbreviateScientificTaxonNames( ( _abbreviate_scientific_names != null )
1278 && _abbreviate_scientific_names.isSelected() );
1279 options.setColorLabelsSameAsParentBranch( ( _color_labels_same_as_parent_branch != null )
1280 && _color_labels_same_as_parent_branch.isSelected() );
1281 options.setShowDefaultNodeShapesInternal( ( _show_default_node_shapes_internal_cbmi != null )
1282 && _show_default_node_shapes_internal_cbmi.isSelected() );
1283 options.setShowDefaultNodeShapesExternal( ( _show_default_node_shapes_external_cbmi != null )
1284 && _show_default_node_shapes_external_cbmi.isSelected() );
1285 options.setTaxonomyColorizeNodeShapes( ( _taxonomy_colorize_node_shapes_cbmi != null )
1286 && _taxonomy_colorize_node_shapes_cbmi.isSelected() );
1287 if ( ( _non_lined_up_cladograms_rbmi != null ) && ( _non_lined_up_cladograms_rbmi.isSelected() ) ) {
1288 options.setCladogramType( CLADOGRAM_TYPE.NON_LINED_UP );
1290 else if ( ( _uniform_cladograms_rbmi != null ) && ( _uniform_cladograms_rbmi.isSelected() ) ) {
1291 options.setCladogramType( CLADOGRAM_TYPE.TOTAL_NODE_SUM_DEP );
1293 else if ( ( _ext_node_dependent_cladogram_rbmi != null ) && ( _ext_node_dependent_cladogram_rbmi.isSelected() ) ) {
1294 options.setCladogramType( CLADOGRAM_TYPE.EXT_NODE_SUM_DEP );
1296 options.setSearchCaseSensitive( ( _search_case_senstive_cbmi != null )
1297 && _search_case_senstive_cbmi.isSelected() );
1298 if ( ( _show_scale_cbmi != null ) && _show_scale_cbmi.isEnabled() ) {
1299 options.setShowScale( _show_scale_cbmi.isSelected() );
1301 if ( _label_direction_cbmi != null ) {
1302 if ( _label_direction_cbmi.isSelected() ) {
1303 options.setNodeLabelDirection( NODE_LABEL_DIRECTION.RADIAL );
1306 options.setNodeLabelDirection( NODE_LABEL_DIRECTION.HORIZONTAL );
1309 options.setShowOverview( ( _show_overview_cbmi != null ) && _show_overview_cbmi.isSelected() );
1310 options.setShowConfidenceStddev( ( _show_confidence_stddev_cbmi != null )
1311 && _show_confidence_stddev_cbmi.isSelected() );
1312 if ( ( _show_branch_length_values_cbmi != null ) && _show_branch_length_values_cbmi.isEnabled() ) {
1313 options.setShowBranchLengthValues( _show_branch_length_values_cbmi.isSelected() );
1315 options.setMatchWholeTermsOnly( ( _search_whole_words_only_cbmi != null )
1316 && _search_whole_words_only_cbmi.isSelected() );
1317 options.setInverseSearchResult( ( _inverse_search_result_cbmi != null )
1318 && _inverse_search_result_cbmi.isSelected() );
1319 if ( ( _rectangular_type_cbmi != null ) && _rectangular_type_cbmi.isSelected() ) {
1320 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR );
1322 else if ( ( _triangular_type_cbmi != null ) && _triangular_type_cbmi.isSelected() ) {
1323 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.TRIANGULAR );
1325 else if ( ( _curved_type_cbmi != null ) && _curved_type_cbmi.isSelected() ) {
1326 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CURVED );
1328 else if ( ( _convex_type_cbmi != null ) && _convex_type_cbmi.isSelected() ) {
1329 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CONVEX );
1331 else if ( ( _euro_type_cbmi != null ) && _euro_type_cbmi.isSelected() ) {
1332 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE );
1334 else if ( ( _rounded_type_cbmi != null ) && _rounded_type_cbmi.isSelected() ) {
1335 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.ROUNDED );
1337 else if ( ( _unrooted_type_cbmi != null ) && _unrooted_type_cbmi.isSelected() ) {
1338 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.UNROOTED );
1340 else if ( ( _circular_type_cbmi != null ) && _circular_type_cbmi.isSelected() ) {
1341 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CIRCULAR );
1345 void updateTypeCheckboxes( final Options options, final Object o ) {
1346 setTypeMenuToAllUnselected();
1347 ( ( JCheckBoxMenuItem ) o ).setSelected( true );
1350 void viewAsNexus() {
1351 if ( ( getMainPanel().getCurrentPhylogeny() != null ) && !getMainPanel().getCurrentPhylogeny().isEmpty() ) {
1352 String title = "Nexus";
1353 if ( !ForesterUtil.isEmpty( getMainPanel().getCurrentPhylogeny().getName() ) ) {
1354 title = getMainPanel().getCurrentPhylogeny().getName() + " " + title;
1356 showTextFrame( getMainPanel().getCurrentPhylogeny().toNexus( getOptions()
1357 .getNhConversionSupportValueStyle() ),
1363 if ( ( getMainPanel().getCurrentPhylogeny() != null ) && !getMainPanel().getCurrentPhylogeny().isEmpty() ) {
1364 String title = "New Hampshire";
1365 if ( !ForesterUtil.isEmpty( getMainPanel().getCurrentPhylogeny().getName() ) ) {
1366 title = getMainPanel().getCurrentPhylogeny().getName() + " " + title;
1368 showTextFrame( getMainPanel().getCurrentPhylogeny()
1369 .toNewHampshire( false, getOptions().getNhConversionSupportValueStyle() ),
1375 if ( ( getMainPanel().getCurrentPhylogeny() != null ) && !getMainPanel().getCurrentPhylogeny().isEmpty() ) {
1376 String title = "phyloXML";
1377 if ( !ForesterUtil.isEmpty( getMainPanel().getCurrentPhylogeny().getName() ) ) {
1378 title = getMainPanel().getCurrentPhylogeny().getName() + " " + title;
1380 showTextFrame( getMainPanel().getCurrentPhylogeny().toPhyloXML( 0 ), title );
1384 private void chooseFont() {
1385 final FontChooser fc = new FontChooser();
1386 fc.setFont( getMainPanel().getTreeFontSet().getLargeFont() );
1387 fc.showDialog( this, "Select the Base Font" );
1388 getMainPanel().getTreeFontSet().setBaseFont( fc.getFont() );
1391 private void chooseMinimalConfidence() {
1392 final String s = ( String ) JOptionPane
1393 .showInputDialog( this,
1394 "Please the minimum for confidence values to be displayed.\n" + "[current value: "
1395 + getOptions().getMinConfidenceValue() + "]\n",
1396 "Minimal Confidence Value",
1397 JOptionPane.QUESTION_MESSAGE,
1400 getOptions().getMinConfidenceValue() );
1401 if ( !ForesterUtil.isEmpty( s ) ) {
1402 boolean success = true;
1404 final String m_str = s.trim();
1405 if ( !ForesterUtil.isEmpty( m_str ) ) {
1407 m = Double.parseDouble( m_str );
1409 catch ( final Exception ex ) {
1416 if ( success && ( m >= 0.0 ) ) {
1417 getOptions().setMinConfidenceValue( m );
1422 private void customizeRadioButtonMenuItem( final JRadioButtonMenuItem item, final boolean is_selected ) {
1423 if ( item != null ) {
1424 item.setFont( MainFrame.menu_font );
1425 if ( !getConfiguration().isUseNativeUI() ) {
1426 item.setBackground( getConfiguration().getGuiMenuBackgroundColor() );
1427 item.setForeground( getConfiguration().getGuiMenuTextColor() );
1429 item.setSelected( is_selected );
1430 item.addActionListener( this );
1434 private MainPanel getMainPanel() {
1438 private Phylogeny getSpeciesTree() {
1439 return _species_tree;
1442 private boolean isScreenAntialias() {
1446 private void removeBranchColors() {
1447 if ( getMainPanel().getCurrentPhylogeny() != null ) {
1448 AptxUtil.removeBranchColors( getMainPanel().getCurrentPhylogeny() );
1452 private void setMainPanel( final MainPanelApplets main_panel ) {
1453 _mainpanel = main_panel;
1456 private void setSpeciesTree( final Phylogeny species_tree ) {
1457 _species_tree = species_tree;
1460 private void setupUI() {
1462 if ( getConfiguration().isUseNativeUI() ) {
1463 UIManager.setLookAndFeel( UIManager.getSystemLookAndFeelClassName() );
1466 UIManager.setLookAndFeel( UIManager.getCrossPlatformLookAndFeelClassName() );
1469 catch ( final UnsupportedLookAndFeelException e ) {
1470 AptxUtil.dieWithSystemError( "UnsupportedLookAndFeelException: " + e.toString() );
1472 catch ( final ClassNotFoundException e ) {
1473 AptxUtil.dieWithSystemError( "ClassNotFoundException: " + e.toString() );
1475 catch ( final InstantiationException e ) {
1476 AptxUtil.dieWithSystemError( "InstantiationException: " + e.toString() );
1478 catch ( final IllegalAccessException e ) {
1479 AptxUtil.dieWithSystemError( "IllegalAccessException: " + e.toString() );
1481 catch ( final Exception e ) {
1482 AptxUtil.dieWithSystemError( e.toString() );
1486 static void setupScreenTextAntialias( final List<TreePanel> treepanels, final boolean antialias ) {
1487 for( final TreePanel tree_panel : treepanels ) {
1488 tree_panel.setTextAntialias();