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() );
466 catch ( final Exception e ) {
467 ForesterUtil.printErrorMessage( NAME, e.toString() );
469 JOptionPane.showMessageDialog( this,
470 NAME + ": Failed to read phylogenies: " + "\nException: " + e,
471 "Failed to read phylogenies",
472 JOptionPane.ERROR_MESSAGE );
475 if ( ( phys == null ) || ( phys.length < 1 ) ) {
476 ForesterUtil.printErrorMessage( NAME, "phylogenies from [" + phys_url + "] are null or empty" );
477 JOptionPane.showMessageDialog( this,
478 NAME + ": phylogenies from [" + phys_url + "] are null or empty",
479 "Failed to read phylogenies",
480 JOptionPane.ERROR_MESSAGE );
484 AptxUtil.printAppletMessage( NAME, "loaded " + phys.length + " phylogenies from: " + phys_url );
487 final String species_tree_url_str = getParameter( Constants.APPLET_PARAM_NAME_FOR_URL_OF_SPECIES_TREE_TO_LOAD );
488 if ( !ForesterUtil.isEmpty( species_tree_url_str ) ) {
489 AptxUtil.printAppletMessage( NAME, "URL of species tree to load: \"" + species_tree_url_str + "\"" );
490 Phylogeny[] species_trees = null;
492 final URL species_tree_url = new URL( species_tree_url_str );
493 species_trees = AptxUtil.readPhylogeniesFromUrl( species_tree_url,
494 configuration.isValidatePhyloXmlAgainstSchema(),
495 configuration.isReplaceUnderscoresInNhParsing(),
497 TAXONOMY_EXTRACTION.NO );
499 catch ( final IOException e ) {
500 ForesterUtil.printErrorMessage( NAME, "could not read species tree from [" + species_tree_url_str
502 JOptionPane.showMessageDialog( this, NAME + ": could not read species tree from ["
503 + species_tree_url_str + "]", "Failed to read species tree", JOptionPane.ERROR_MESSAGE );
505 if ( ( species_trees != null ) && ( species_trees.length > 0 ) ) {
506 AptxUtil.printAppletMessage( NAME, "successfully read species tree" );
507 if ( species_trees[ 0 ].isEmpty() ) {
508 ForesterUtil.printErrorMessage( NAME, "species tree is empty" );
510 else if ( !species_trees[ 0 ].isRooted() ) {
511 ForesterUtil.printErrorMessage( NAME, "species tree is not rooted" );
514 setSpeciesTree( species_trees[ 0 ] );
520 setMainPanel( new MainPanelApplets( getConfiguration(), this ) );
521 _jmenubar = new JMenuBar();
522 if ( !getConfiguration().isHideControlPanelAndMenubar() ) {
523 if ( !getConfiguration().isUseNativeUI() ) {
524 _jmenubar.setBackground( getConfiguration().getGuiMenuBackgroundColor() );
526 if ( getSpeciesTree() != null ) {
535 setJMenuBar( _jmenubar );
537 final Container contentpane = getContentPane();
538 contentpane.setLayout( new BorderLayout() );
539 contentpane.add( getMainPanel(), BorderLayout.CENTER );
540 addComponentListener( new ComponentAdapter() {
543 public void componentResized( final ComponentEvent e ) {
544 if ( getMainPanel().getCurrentTreePanel() != null ) {
545 getMainPanel().getCurrentTreePanel().calcParametersForPainting( getMainPanel()
546 .getCurrentTreePanel()
549 .getCurrentTreePanel()
552 .isAllowFontSizeChange() );
556 if ( getConfiguration().isUseTabbedDisplay() ) {
557 AptxUtil.printAppletMessage( NAME, "using tabbed display" );
558 AptxUtil.addPhylogeniesToTabs( phys,
559 new File( phys_url.getFile() ).getName(),
565 AptxUtil.printAppletMessage( NAME, "not using tabbed display" );
566 AptxUtil.addPhylogenyToPanel( phys, getConfiguration(), getMainPanel() );
570 getMainPanel().getControlPanel().showWholeAll();
571 getMainPanel().getControlPanel().showWhole();
573 AptxUtil.printAppletMessage( NAME, "successfully initialized" );
575 getCurrentTreePanel().getControlPanel().getSequenceRelationTypeBox().removeAllItems();
576 for( final SequenceRelation.SEQUENCE_RELATION_TYPE type : getMainPanel().getCurrentPhylogeny()
577 .getRelevantSequenceRelationTypes() ) {
578 getCurrentTreePanel().getControlPanel().getSequenceRelationTypeBox().addItem( type );
580 final String default_relation = getParameter( Constants.APPLET_PARAM_NAME_FOR_DEFAULT_SEQUENCE_RELATION_TYPE );
581 if ( default_relation != null ) {
582 getCurrentTreePanel().getControlPanel().getSequenceRelationTypeBox().setSelectedItem( default_relation );
584 final String default_sequence = getParameter( Constants.APPLET_PARAM_NAME_FOR_DEFAULT_QUERY_SEQUENCE );
585 if ( default_sequence != null ) {
586 getCurrentTreePanel().getControlPanel().getSequenceRelationBox().setSelectedItem( default_sequence );
592 public void showTextFrame( final String s, final String title ) {
594 _textframes.addLast( TextFrame.instantiate( s, title, _textframes ) );
598 public void start() {
599 if ( getMainPanel() != null ) {
600 getMainPanel().validate();
603 requestFocusInWindow();
605 AptxUtil.printAppletMessage( NAME, "started" );
608 void buildAnalysisMenu() {
609 _analysis_menu = MainFrame.createMenu( "Analysis", getConfiguration() );
610 _analysis_menu.add( _gsdi_item = new JMenuItem( "GSDI (Generalized Speciation Duplication Inference)" ) );
611 _analysis_menu.add( _gsdir_item = new JMenuItem( "GSDIR (GSDI with re-rooting)" ) );
612 customizeJMenuItem( _gsdi_item );
613 customizeJMenuItem( _gsdir_item );
614 // _analysis_menu.addSeparator();
615 // _analysis_menu.add( _lineage_inference = new JMenuItem( INFER_ANCESTOR_TAXONOMIES ) );
616 // customizeJMenuItem( _lineage_inference );
617 // _lineage_inference.setToolTipText( "Inference of ancestor taxonomies/lineages" );
618 _jmenubar.add( _analysis_menu );
621 void buildFontSizeMenu() {
622 _font_size_menu = MainFrame.createMenu( MainFrame.FONT_SIZE_MENU_LABEL, getConfiguration() );
623 _font_size_menu.add( _super_tiny_fonts_mi = new JMenuItem( "Super tiny fonts" ) );
624 _font_size_menu.add( _tiny_fonts_mi = new JMenuItem( "Tiny fonts" ) );
625 _font_size_menu.add( _small_fonts_mi = new JMenuItem( "Small fonts" ) );
626 _font_size_menu.add( _medium_fonts_mi = new JMenuItem( "Medium fonts" ) );
627 _font_size_menu.add( _large_fonts_mi = new JMenuItem( "Large fonts" ) );
628 customizeJMenuItem( _super_tiny_fonts_mi );
629 customizeJMenuItem( _tiny_fonts_mi );
630 customizeJMenuItem( _small_fonts_mi );
631 customizeJMenuItem( _medium_fonts_mi );
632 customizeJMenuItem( _large_fonts_mi );
633 _jmenubar.add( _font_size_menu );
636 void buildHelpMenu() {
637 _help_jmenu = MainFrame.createMenu( "Help", getConfiguration() );
638 _help_jmenu.add( _help_item = new JMenuItem( "Help" ) );
639 _help_jmenu.add( _website_item = new JMenuItem( "Archaeopteryx Home" ) );
640 _aptx_ref_item = new JMenuItem( "Archaeopteryx Reference" );
641 _help_jmenu.add( _phyloxml_website_item = new JMenuItem( "phyloXML Home" ) );
642 _help_jmenu.add( _phyloxml_ref_item = new JMenuItem( "phyloXML Reference" ) );
643 _help_jmenu.addSeparator();
644 _help_jmenu.add( _about_item = new JMenuItem( "About" ) );
645 customizeJMenuItem( _help_item );
646 customizeJMenuItem( _website_item );
647 customizeJMenuItem( _phyloxml_website_item );
648 customizeJMenuItem( _aptx_ref_item );
649 customizeJMenuItem( _phyloxml_ref_item );
650 customizeJMenuItem( _about_item );
651 _phyloxml_ref_item.setToolTipText( MainFrame.PHYLOXML_REF_TOOL_TIP );
652 _aptx_ref_item.setToolTipText( MainFrame.APTX_REF_TOOL_TIP );
653 _jmenubar.add( _help_jmenu );
656 void buildOptionsMenu() {
657 _options_jmenu = MainFrame.createMenu( MainFrame.OPTIONS_HEADER, getConfiguration() );
658 _options_jmenu.addChangeListener( new ChangeListener() {
661 public void stateChanged( final ChangeEvent e ) {
662 MainFrame.setOvPlacementColorChooseMenuItem( _overview_placment_mi, getOptions() );
663 MainFrame.setTextColorChooseMenuItem( _switch_colors_mi, getCurrentTreePanel() );
665 .setTextMinSupportMenuItem( _choose_minimal_confidence_mi, getOptions(), getCurrentTreePanel() );
666 MainFrame.setTextForFontChooserMenuItem( _choose_font_mi, MainFrame
667 .createCurrentFontDesc( getMainPanel().getTreeFontSet() ) );
668 MainFrame.updateOptionsMenuDependingOnPhylogenyType( getMainPanel(),
670 _show_branch_length_values_cbmi,
671 _non_lined_up_cladograms_rbmi,
672 _uniform_cladograms_rbmi,
673 _ext_node_dependent_cladogram_rbmi,
674 _label_direction_cbmi );
675 MainFrame.setCycleNodeFillMenuItem( _cycle_node_fill_mi, getOptions() );
676 MainFrame.setCycleNodeShapeMenuItem( _cycle_node_shape_mi, getOptions() );
677 MainFrame.setTextNodeSizeMenuItem( _choose_node_size_mi, getOptions() );
680 _options_jmenu.add( MainFrame.customizeMenuItemAsLabel( new JMenuItem( MainFrame.DISPLAY_SUBHEADER ),
681 getConfiguration() ) );
683 .add( _ext_node_dependent_cladogram_rbmi = new JRadioButtonMenuItem( MainFrame.NONUNIFORM_CLADOGRAMS_LABEL ) );
684 _options_jmenu.add( _uniform_cladograms_rbmi = new JRadioButtonMenuItem( MainFrame.UNIFORM_CLADOGRAMS_LABEL ) );
686 .add( _non_lined_up_cladograms_rbmi = new JRadioButtonMenuItem( MainFrame.NON_LINED_UP_CLADOGRAMS_LABEL ) );
687 _radio_group_1 = new ButtonGroup();
688 _radio_group_1.add( _ext_node_dependent_cladogram_rbmi );
689 _radio_group_1.add( _uniform_cladograms_rbmi );
690 _radio_group_1.add( _non_lined_up_cladograms_rbmi );
691 _options_jmenu.add( _show_overview_cbmi = new JCheckBoxMenuItem( MainFrame.SHOW_OVERVIEW_LABEL ) );
692 _options_jmenu.add( _show_scale_cbmi = new JCheckBoxMenuItem( MainFrame.DISPLAY_SCALE_LABEL ) );
694 .add( _show_branch_length_values_cbmi = new JCheckBoxMenuItem( MainFrame.DISPLAY_BRANCH_LENGTH_VALUES_LABEL ) );
695 _options_jmenu.add( _show_confidence_stddev_cbmi = new JCheckBoxMenuItem( MainFrame.SHOW_CONF_STDDEV_LABEL ) );
697 .add( _show_default_node_shapes_internal_cbmi = new JCheckBoxMenuItem( MainFrame.DISPLAY_NODE_BOXES_LABEL_INT ) );
699 .add( _show_default_node_shapes_external_cbmi = new JCheckBoxMenuItem( MainFrame.DISPLAY_NODE_BOXES_LABEL_EXT ) );
701 .add( _taxonomy_colorize_node_shapes_cbmi = new JCheckBoxMenuItem( MainFrame.TAXONOMY_COLORIZE_NODE_SHAPES_LABEL ) );
702 _options_jmenu.add( _cycle_node_shape_mi = new JMenuItem( MainFrame.CYCLE_NODE_SHAPE_LABEL ) );
703 _options_jmenu.add( _cycle_node_fill_mi = new JMenuItem( MainFrame.CYCLE_NODE_FILL_LABEL ) );
704 _options_jmenu.add( _choose_node_size_mi = new JMenuItem( MainFrame.CHOOSE_NODE_SIZE_LABEL ) );
705 _options_jmenu.add( _label_direction_cbmi = new JCheckBoxMenuItem( MainFrame.LABEL_DIRECTION_LABEL ) );
707 .add( _color_labels_same_as_parent_branch = new JCheckBoxMenuItem( MainFrame.COLOR_LABELS_LABEL ) );
708 _color_labels_same_as_parent_branch.setToolTipText( MainFrame.COLOR_LABELS_TIP );
709 _options_jmenu.add( _abbreviate_scientific_names = new JCheckBoxMenuItem( MainFrame.ABBREV_SN_LABEL ) );
710 _label_direction_cbmi.setToolTipText( MainFrame.LABEL_DIRECTION_TIP );
711 _options_jmenu.add( _screen_antialias_cbmi = new JCheckBoxMenuItem( MainFrame.SCREEN_ANTIALIAS_LABEL ) );
712 _options_jmenu.add( _background_gradient_cbmi = new JCheckBoxMenuItem( MainFrame.BG_GRAD_LABEL ) );
713 if ( getConfiguration().doDisplayOption( Configuration.show_domain_architectures ) ) {
714 _options_jmenu.add( _show_domain_labels = new JCheckBoxMenuItem( MainFrame.SHOW_DOMAIN_LABELS_LABEL ) );
716 _options_jmenu.add( _choose_minimal_confidence_mi = new JMenuItem( "" ) );
717 _options_jmenu.add( _overview_placment_mi = new JMenuItem( "" ) );
718 _options_jmenu.add( _switch_colors_mi = new JMenuItem( "" ) );
719 _options_jmenu.add( _choose_font_mi = new JMenuItem( "" ) );
720 _options_jmenu.addSeparator();
721 _options_jmenu.add( MainFrame.customizeMenuItemAsLabel( new JMenuItem( MainFrame.SEARCH_SUBHEADER ),
722 getConfiguration() ) );
724 .add( _search_case_senstive_cbmi = new JCheckBoxMenuItem( MainFrame.SEARCH_CASE_SENSITIVE_LABEL ) );
725 _options_jmenu.add( _search_whole_words_only_cbmi = new JCheckBoxMenuItem( MainFrame.SEARCH_TERMS_ONLY_LABEL ) );
727 .add( _inverse_search_result_cbmi = new JCheckBoxMenuItem( MainFrame.INVERSE_SEARCH_RESULT_LABEL ) );
728 customizeJMenuItem( _choose_font_mi );
729 customizeJMenuItem( _choose_minimal_confidence_mi );
730 customizeJMenuItem( _switch_colors_mi );
731 customizeJMenuItem( _overview_placment_mi );
732 customizeCheckBoxMenuItem( _label_direction_cbmi,
733 getOptions().getNodeLabelDirection() == NODE_LABEL_DIRECTION.RADIAL );
734 customizeCheckBoxMenuItem( _screen_antialias_cbmi, getOptions().isAntialiasScreen() );
735 customizeCheckBoxMenuItem( _background_gradient_cbmi, getOptions().isBackgroundColorGradient() );
736 customizeCheckBoxMenuItem( _show_domain_labels, getOptions().isShowDomainLabels() );
737 customizeCheckBoxMenuItem( _abbreviate_scientific_names, getOptions().isAbbreviateScientificTaxonNames() );
738 customizeCheckBoxMenuItem( _show_default_node_shapes_external_cbmi, getOptions()
739 .isShowDefaultNodeShapesExternal() );
740 customizeCheckBoxMenuItem( _show_default_node_shapes_internal_cbmi, getOptions()
741 .isShowDefaultNodeShapesInternal() );
742 customizeCheckBoxMenuItem( _taxonomy_colorize_node_shapes_cbmi, getOptions().isTaxonomyColorizeNodeShapes() );
743 customizeJMenuItem( _cycle_node_shape_mi );
744 customizeJMenuItem( _cycle_node_fill_mi );
745 customizeJMenuItem( _choose_node_size_mi );
746 customizeCheckBoxMenuItem( _color_labels_same_as_parent_branch, getOptions().isColorLabelsSameAsParentBranch() );
747 customizeCheckBoxMenuItem( _search_case_senstive_cbmi, getOptions().isSearchCaseSensitive() );
748 customizeCheckBoxMenuItem( _show_scale_cbmi, getOptions().isShowScale() );
749 customizeRadioButtonMenuItem( _non_lined_up_cladograms_rbmi,
750 getOptions().getCladogramType() == CLADOGRAM_TYPE.NON_LINED_UP );
751 customizeRadioButtonMenuItem( _uniform_cladograms_rbmi,
752 getOptions().getCladogramType() == CLADOGRAM_TYPE.TOTAL_NODE_SUM_DEP );
753 customizeRadioButtonMenuItem( _ext_node_dependent_cladogram_rbmi,
754 getOptions().getCladogramType() == CLADOGRAM_TYPE.EXT_NODE_SUM_DEP );
755 customizeCheckBoxMenuItem( _show_branch_length_values_cbmi, getOptions().isShowBranchLengthValues() );
756 customizeCheckBoxMenuItem( _show_overview_cbmi, getOptions().isShowOverview() );
757 customizeCheckBoxMenuItem( _search_whole_words_only_cbmi, getOptions().isMatchWholeTermsOnly() );
758 customizeCheckBoxMenuItem( _inverse_search_result_cbmi, getOptions().isInverseSearchResult() );
759 customizeCheckBoxMenuItem( _show_confidence_stddev_cbmi, getOptions().isShowConfidenceStddev() );
760 _jmenubar.add( _options_jmenu );
763 void buildToolsMenu() {
764 _tools_menu = MainFrame.createMenu( "Tools", getConfiguration() );
765 _tools_menu.add( _confcolor_item = new JMenuItem( "Colorize Branches Depending on Confidence" ) );
766 customizeJMenuItem( _confcolor_item );
767 _tools_menu.add( _taxcolor_item = new JMenuItem( "Taxonomy Colorize Branches" ) );
768 customizeJMenuItem( _taxcolor_item );
769 _tools_menu.add( _remove_branch_color_item = new JMenuItem( "Delete Branch Colors" ) );
770 _remove_branch_color_item.setToolTipText( "To delete branch color values from the current phylogeny." );
771 customizeJMenuItem( _remove_branch_color_item );
772 _tools_menu.addSeparator();
773 _tools_menu.add( _midpoint_root_item = new JMenuItem( "Midpoint-Root" ) );
774 customizeJMenuItem( _midpoint_root_item );
775 _tools_menu.addSeparator();
776 _tools_menu.add( _collapse_species_specific_subtrees = new JMenuItem( "Collapse Species-Specific Subtrees" ) );
777 customizeJMenuItem( _collapse_species_specific_subtrees );
778 _jmenubar.add( _tools_menu );
781 void buildTypeMenu() {
782 _type_menu = MainFrame.createMenu( MainFrame.TYPE_MENU_HEADER, getConfiguration() );
783 _type_menu.add( _rectangular_type_cbmi = new JCheckBoxMenuItem( MainFrame.RECTANGULAR_TYPE_CBMI_LABEL ) );
784 _type_menu.add( _euro_type_cbmi = new JCheckBoxMenuItem( MainFrame.EURO_TYPE_CBMI_LABEL ) );
785 _type_menu.add( _rounded_type_cbmi = new JCheckBoxMenuItem( MainFrame.ROUNDED_TYPE_CBMI_LABEL ) );
786 _type_menu.add( _curved_type_cbmi = new JCheckBoxMenuItem( MainFrame.CURVED_TYPE_CBMI_LABEL ) );
787 _type_menu.add( _triangular_type_cbmi = new JCheckBoxMenuItem( MainFrame.TRIANGULAR_TYPE_CBMI_LABEL ) );
788 _type_menu.add( _convex_type_cbmi = new JCheckBoxMenuItem( MainFrame.CONVEX_TYPE_CBMI_LABEL ) );
789 _type_menu.add( _unrooted_type_cbmi = new JCheckBoxMenuItem( MainFrame.UNROOTED_TYPE_CBMI_LABEL ) );
790 _type_menu.add( _circular_type_cbmi = new JCheckBoxMenuItem( MainFrame.CIRCULAR_TYPE_CBMI_LABEL ) );
791 customizeCheckBoxMenuItem( _rectangular_type_cbmi, false );
792 customizeCheckBoxMenuItem( _triangular_type_cbmi, false );
793 customizeCheckBoxMenuItem( _euro_type_cbmi, false );
794 customizeCheckBoxMenuItem( _rounded_type_cbmi, false );
795 customizeCheckBoxMenuItem( _curved_type_cbmi, false );
796 customizeCheckBoxMenuItem( _convex_type_cbmi, false );
797 customizeCheckBoxMenuItem( _unrooted_type_cbmi, false );
798 customizeCheckBoxMenuItem( _circular_type_cbmi, false );
799 _unrooted_type_cbmi.setToolTipText( MainFrame.USE_MOUSEWHEEL_SHIFT_TO_ROTATE );
800 _circular_type_cbmi.setToolTipText( MainFrame.USE_MOUSEWHEEL_SHIFT_TO_ROTATE );
801 initializeTypeMenu( getOptions() );
802 _jmenubar.add( _type_menu );
805 void buildViewMenu() {
806 _view_jmenu = MainFrame.createMenu( "View", getConfiguration() );
807 _view_jmenu.add( _display_basic_information_item = new JMenuItem( "Display Basic Information" ) );
808 _view_jmenu.addSeparator();
809 _view_jmenu.add( _view_as_XML_item = new JMenuItem( "View as phyloXML" ) );
810 _view_jmenu.add( _view_as_NH_item = new JMenuItem( "View as Newick" ) );
811 _view_jmenu.add( _view_as_nexus_item = new JMenuItem( "View as Nexus" ) );
812 customizeJMenuItem( _display_basic_information_item );
813 customizeJMenuItem( _view_as_NH_item );
814 customizeJMenuItem( _view_as_XML_item );
815 customizeJMenuItem( _view_as_nexus_item );
816 _jmenubar.add( _view_jmenu );
819 void checkTextFrames() {
820 if ( _textframes.size() > 5 ) {
822 if ( _textframes.getFirst() != null ) {
823 _textframes.getFirst().removeMe();
826 _textframes.removeFirst();
829 catch ( final NoSuchElementException e ) {
835 void clearCurrentExternalNodesDataBuffer() {
836 getCurrentTreePanel().clearCurrentExternalNodesDataBuffer();
839 void customizeCheckBoxMenuItem( final JCheckBoxMenuItem item, final boolean is_selected ) {
840 if ( item != null ) {
841 item.setFont( MainFrame.menu_font );
842 if ( !getConfiguration().isUseNativeUI() ) {
843 item.setBackground( getConfiguration().getGuiMenuBackgroundColor() );
844 item.setForeground( getConfiguration().getGuiMenuTextColor() );
846 item.setSelected( is_selected );
847 item.addActionListener( this );
851 void customizeJMenuItem( final JMenuItem jmi ) {
852 jmi.setFont( MainFrame.menu_font );
853 if ( !getConfiguration().isUseNativeUI() ) {
854 jmi.setBackground( getConfiguration().getGuiMenuBackgroundColor() );
855 jmi.setForeground( getConfiguration().getGuiMenuTextColor() );
857 jmi.addActionListener( this );
860 void displayBasicInformation() {
861 if ( ( getMainPanel().getCurrentPhylogeny() != null ) && !getMainPanel().getCurrentPhylogeny().isEmpty() ) {
862 String title = "Basic Information";
863 if ( !ForesterUtil.isEmpty( getMainPanel().getCurrentPhylogeny().getName() ) ) {
864 title = getMainPanel().getCurrentPhylogeny().getName() + " " + title;
866 showTextFrame( AptxUtil.createBasicInformation( getMainPanel().getCurrentPhylogeny() ), title );
871 if ( !isOKforSDI( false, true ) ) {
874 if ( !_mainpanel.getCurrentPhylogeny().isRooted() ) {
875 JOptionPane.showMessageDialog( this,
876 "Gene tree is not rooted.",
877 "Cannot execute GSDI",
878 JOptionPane.ERROR_MESSAGE );
881 final Phylogeny gene_tree = _mainpanel.getCurrentPhylogeny().copy();
882 gene_tree.setAllNodesToNotCollapse();
883 gene_tree.recalculateNumberOfExternalDescendants( false );
885 final Phylogeny species_tree = _species_tree.copy();
887 gsdi = new GSDI( gene_tree, species_tree, false, true, true );
889 catch ( final SDIException e ) {
890 JOptionPane.showMessageDialog( this,
891 e.getLocalizedMessage(),
893 JOptionPane.ERROR_MESSAGE );
896 catch ( final Exception e ) {
897 AptxUtil.unexpectedException( e );
900 gene_tree.setRerootable( false );
901 gene_tree.clearHashIdToNodeMap();
902 gene_tree.recalculateNumberOfExternalDescendants( true );
903 _mainpanel.addPhylogenyInNewTab( gene_tree, getConfiguration(), "gene tree", null );
904 getMainPanel().getControlPanel().setShowEvents( true );
906 final int selected = _mainpanel.getTabbedPane().getSelectedIndex();
907 _mainpanel.addPhylogenyInNewTab( species_tree, getConfiguration(), "species tree", null );
909 _mainpanel.getTabbedPane().setSelectedIndex( selected );
911 _mainpanel.getCurrentTreePanel().setEdited( true );
912 final int poly = PhylogenyMethods.countNumberOfPolytomies( species_tree );
913 if ( gsdi.getStrippedExternalGeneTreeNodes().size() > 0 ) {
914 JOptionPane.showMessageDialog( this,
915 "Duplications: " + gsdi.getDuplicationsSum() + "\n"
916 + "Potential duplications: "
917 + gsdi.getSpeciationOrDuplicationEventsSum() + "\n"
918 + "Speciations: " + gsdi.getSpeciationsSum() + "\n"
919 + "Stripped gene tree nodes: "
920 + gsdi.getStrippedExternalGeneTreeNodes().size() + "\n"
921 + "Taxonomy linkage based on: " + gsdi.getTaxCompBase() + "\n"
922 + "Number of polytomies in species tree used: " + poly + "\n",
923 "GSDI successfully completed",
924 JOptionPane.WARNING_MESSAGE );
927 JOptionPane.showMessageDialog( this,
928 "Duplications: " + gsdi.getDuplicationsSum() + "\n"
929 + "Potential duplications: "
930 + gsdi.getSpeciationOrDuplicationEventsSum() + "\n"
931 + "Speciations: " + gsdi.getSpeciationsSum() + "\n"
932 + "Stripped gene tree nodes: "
933 + gsdi.getStrippedExternalGeneTreeNodes().size() + "\n"
934 + "Taxonomy linkage based on: " + gsdi.getTaxCompBase() + "\n"
935 + "Number of polytomies in species tree used: " + poly + "\n",
936 "GSDI successfully completed",
937 JOptionPane.INFORMATION_MESSAGE );
941 void executeGSDIR() {
942 if ( !isOKforSDI( false, false ) ) {
945 final int p = PhylogenyMethods.countNumberOfPolytomies( _mainpanel.getCurrentPhylogeny() );
947 && !( ( p == 1 ) && ( _mainpanel.getCurrentPhylogeny().getRoot().getNumberOfDescendants() == 3 ) ) ) {
948 JOptionPane.showMessageDialog( this,
949 "Gene tree is not completely binary",
950 "Cannot execute GSDI",
951 JOptionPane.ERROR_MESSAGE );
954 final Phylogeny gene_tree = _mainpanel.getCurrentPhylogeny().copy();
955 gene_tree.setAllNodesToNotCollapse();
956 gene_tree.recalculateNumberOfExternalDescendants( false );
958 final Phylogeny species_tree = _species_tree.copy();
960 gsdir = new GSDIR( gene_tree, species_tree, true, true );
962 catch ( final SDIException e ) {
963 JOptionPane.showMessageDialog( this,
964 e.getLocalizedMessage(),
965 "Error during GSDIR",
966 JOptionPane.ERROR_MESSAGE );
969 catch ( final Exception e ) {
970 AptxUtil.unexpectedException( e );
973 final Phylogeny result_gene_tree = gsdir.getMinDuplicationsSumGeneTree();
974 result_gene_tree.setRerootable( false );
975 result_gene_tree.clearHashIdToNodeMap();
976 result_gene_tree.recalculateNumberOfExternalDescendants( true );
977 _mainpanel.addPhylogenyInNewTab( result_gene_tree, getConfiguration(), "gene tree", null );
978 getMainPanel().getControlPanel().setShowEvents( true );
980 final int selected = _mainpanel.getTabbedPane().getSelectedIndex();
981 _mainpanel.addPhylogenyInNewTab( species_tree, getConfiguration(), "species tree", null );
983 _mainpanel.getTabbedPane().setSelectedIndex( selected );
985 _mainpanel.getCurrentTreePanel().setEdited( true );
986 final int poly = PhylogenyMethods.countNumberOfPolytomies( species_tree );
987 if ( gsdir.getStrippedExternalGeneTreeNodes().size() > 0 ) {
988 JOptionPane.showMessageDialog( this,
989 "Minimal duplications: " + gsdir.getMinDuplicationsSum() + "\n"
990 + "Speciations: " + gsdir.getSpeciationsSum() + "\n"
991 + "Stripped gene tree nodes: "
992 + gsdir.getStrippedExternalGeneTreeNodes().size() + "\n"
993 + "Taxonomy linkage based on: " + gsdir.getTaxCompBase() + "\n"
994 + "Number of polytomies in species tree used: " + poly + "\n",
995 "GSDIR successfully completed",
996 JOptionPane.WARNING_MESSAGE );
999 JOptionPane.showMessageDialog( this,
1000 "Minimal duplications: " + gsdir.getMinDuplicationsSum() + "\n"
1001 + "Speciations: " + gsdir.getSpeciationsSum() + "\n"
1002 + "Stripped gene tree nodes: "
1003 + gsdir.getStrippedExternalGeneTreeNodes().size() + "\n"
1004 + "Taxonomy linkage based on: " + gsdir.getTaxCompBase() + "\n"
1005 + "Number of polytomies in species tree used: " + poly + "\n",
1006 "GSDIR successfully completed",
1007 JOptionPane.INFORMATION_MESSAGE );
1011 Configuration getConfiguration() {
1012 return _configuration;
1015 TreePanel getCurrentTreePanel() {
1016 return getMainPanel().getCurrentTreePanel();
1019 JCheckBoxMenuItem getlabelDirectionCbmi() {
1020 return _label_direction_cbmi;
1023 Options getOtions() {
1028 final StringBuilder sb = new StringBuilder();
1029 sb.append( "Display options\n" );
1030 sb.append( "-------------------\n" );
1031 sb.append( "Use the checkboxes to select types of information to display on the tree.\n\n" );
1032 sb.append( "Clickable tree nodes\n" );
1033 sb.append( "--------------------\n" );
1034 sb.append( "Tree nodes can be clicked, the action is determined by the 'click on node to' menu\n" );
1035 sb.append( "or by right clicking:\n" );
1036 sb.append( "o Display Node Data -- display information for a node\n" );
1037 sb.append( "o Collapse/Uncollapse -- collapse and uncollapse subtree from clicked node\n" );
1038 sb.append( "o Root/Reroot -- change tree root to clicked node\n" );
1039 sb.append( "o Sub/Super Tree -- toggle between subtree from clicked node and whole tree\n" );
1040 sb.append( "o Swap Descendants -- switch descendant on either side of clicked node\n" );
1041 sb.append( "o Colorize Subtree -- color a subtree\n" );
1042 sb.append( "o Open Sequence Web -- launch a web browser to display sequence information\n" );
1043 sb.append( "o Open Taxonomy Web -- launch a web browser to display taxonomy information\n" );
1044 sb.append( "- there may be additional choices depending on this particular setup\n\n" );
1045 sb.append( "Right clicking on a node always displays the information of a node.\n\n" );
1046 sb.append( "Zooming\n" );
1047 sb.append( "---------\n" );
1048 sb.append( "The mouse wheel and the plus and minus keys control zooming.\n" );
1049 sb.append( "Mouse wheel+Ctrl changes the text size.\n" );
1050 sb.append( "Mouse wheel+Shift controls zooming in vertical direction only.\n" );
1051 sb.append( "Use the buttons on the control panel to zoom the tree in and out, horizontally or vertically.\n" );
1052 sb.append( "The entire tree can be fitted into the window by clicking the \"F\" button, or by pressing F, Delete, or Home.\n" );
1053 sb.append( "The up, down, left, and right keys can be used to move the visible part (if zoomed in).\n" );
1054 sb.append( "Up, down, left, and right+Shift can be used to control zooming horizontally and vertically.\n" );
1055 sb.append( "Plus and minus keys+Ctrl change the text size; F+Ctrl, Delete+Ctrl, or Home+Ctrl resets it.\n\n" );
1056 sb.append( "Quick tree manipulation:\n" );
1057 sb.append( "------------------------\n" );
1058 sb.append( "Order Subtrees -- order the tree by branch length\n" );
1059 sb.append( "Uncollapse All -- uncollapse any and all collapsed branches\n\n" );
1060 sb.append( "phyloXML\n" );
1061 sb.append( "-------------------\n" );
1062 sb.append( "Reference: " + Constants.PHYLOXML_REFERENCE + "\n" );
1063 sb.append( "Website: " + Constants.PHYLOXML_WEB_SITE + "\n" );
1064 sb.append( "Version: " + ForesterConstants.PHYLO_XML_VERSION + "\n" );
1066 sb.append( "For more information: http://www.phylosoft.org/archaeopteryx/\n" );
1067 sb.append( "Email: " + Constants.AUTHOR_EMAIL + "\n\n" );
1068 TextFrame.instantiate( sb.toString(), "Help", _textframes );
1071 void initializeTypeMenu( final Options options ) {
1072 setTypeMenuToAllUnselected();
1074 switch ( options.getPhylogenyGraphicsType() ) {
1076 _convex_type_cbmi.setSelected( true );
1079 _curved_type_cbmi.setSelected( true );
1082 _euro_type_cbmi.setSelected( true );
1085 _rounded_type_cbmi.setSelected( true );
1088 _triangular_type_cbmi.setSelected( true );
1091 _unrooted_type_cbmi.setSelected( true );
1094 _circular_type_cbmi.setSelected( true );
1097 _rectangular_type_cbmi.setSelected( true );
1101 catch ( final NullPointerException np ) {
1102 // In all likelihood, this is caused by menu-less display.
1106 boolean isOKforSDI( final boolean species_tree_has_to_binary, final boolean gene_tree_has_to_binary ) {
1107 if ( ( _mainpanel.getCurrentPhylogeny() == null ) || _mainpanel.getCurrentPhylogeny().isEmpty() ) {
1110 else if ( ( _species_tree == null ) || _species_tree.isEmpty() ) {
1111 JOptionPane.showMessageDialog( this,
1112 "No species tree loaded",
1113 "Cannot execute GSDI",
1114 JOptionPane.ERROR_MESSAGE );
1117 else if ( species_tree_has_to_binary && !_species_tree.isCompletelyBinary() ) {
1118 JOptionPane.showMessageDialog( this,
1119 "Species tree is not completely binary",
1120 "Cannot execute GSDI",
1121 JOptionPane.ERROR_MESSAGE );
1124 else if ( gene_tree_has_to_binary && !_mainpanel.getCurrentPhylogeny().isCompletelyBinary() ) {
1125 JOptionPane.showMessageDialog( this,
1126 "Gene tree is not completely binary",
1127 "Cannot execute GSDI",
1128 JOptionPane.ERROR_MESSAGE );
1136 boolean isSubtreeDisplayed() {
1137 if ( getCurrentTreePanel() != null ) {
1138 if ( getCurrentTreePanel().isCurrentTreeIsSubtree() ) {
1140 .showMessageDialog( this,
1141 "This operation can only be performed on a complete tree, not on the currently displayed sub-tree only.",
1142 "Operation can not be exectuted on a sub-tree",
1143 JOptionPane.WARNING_MESSAGE );
1150 void removeAllTextFrames() {
1151 for( final TextFrame tf : _textframes ) {
1156 _textframes.clear();
1159 void setConfiguration( final Configuration configuration ) {
1160 _configuration = configuration;
1163 void setOptions( final Options options ) {
1167 void setSelectedTypeInTypeMenu( final PHYLOGENY_GRAPHICS_TYPE type ) {
1168 setTypeMenuToAllUnselected();
1172 _circular_type_cbmi.setSelected( true );
1175 _convex_type_cbmi.setSelected( true );
1178 _curved_type_cbmi.setSelected( true );
1181 _euro_type_cbmi.setSelected( true );
1184 _rounded_type_cbmi.setSelected( true );
1187 _rectangular_type_cbmi.setSelected( true );
1190 _triangular_type_cbmi.setSelected( true );
1193 _unrooted_type_cbmi.setSelected( true );
1196 throw new IllegalArgumentException( "unknown type: " + type );
1199 catch ( final NullPointerException np ) {
1200 // In all likelihood, this is caused by menu-less display.
1204 void setTypeMenuToAllUnselected() {
1205 if ( _convex_type_cbmi != null ) {
1206 _convex_type_cbmi.setSelected( false );
1208 if ( _curved_type_cbmi != null ) {
1209 _curved_type_cbmi.setSelected( false );
1211 if ( _euro_type_cbmi != null ) {
1212 _euro_type_cbmi.setSelected( false );
1214 if ( _rounded_type_cbmi != null ) {
1215 _rounded_type_cbmi.setSelected( false );
1217 if ( _triangular_type_cbmi != null ) {
1218 _triangular_type_cbmi.setSelected( false );
1220 if ( _rectangular_type_cbmi != null ) {
1221 _rectangular_type_cbmi.setSelected( false );
1223 if ( _unrooted_type_cbmi != null ) {
1224 _unrooted_type_cbmi.setSelected( false );
1226 if ( _circular_type_cbmi != null ) {
1227 _circular_type_cbmi.setSelected( false );
1232 _mainpanel.getControlPanel().showWhole();
1235 void switchColors() {
1236 final TreeColorSet colorset = getMainPanel().getCurrentTreePanel().getTreeColorSet();
1237 final ColorSchemeChooser csc = new ColorSchemeChooser( getMainPanel(), colorset );
1238 csc.setVisible( true );
1239 getMainPanel().setTreeColorSet( colorset );
1242 void typeChanged( final Object o ) {
1243 updateTypeCheckboxes( getOptions(), o );
1244 updateOptions( getOptions() );
1245 if ( getCurrentTreePanel() != null ) {
1246 final PHYLOGENY_GRAPHICS_TYPE previous_type = getCurrentTreePanel().getPhylogenyGraphicsType();
1247 final PHYLOGENY_GRAPHICS_TYPE new_type = getOptions().getPhylogenyGraphicsType();
1248 if ( ( ( previous_type == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) && ( new_type != PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) )
1249 || ( ( previous_type == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) && ( new_type != PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) )
1250 || ( ( previous_type != PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) && ( new_type == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) )
1251 || ( ( previous_type != PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) && ( new_type == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) ) ) {
1252 getCurrentTreePanel().getControlPanel().showWhole();
1254 if ( getCurrentTreePanel().isPhyHasBranchLengths() && ( new_type != PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) ) {
1255 getCurrentTreePanel().getControlPanel().setDrawPhylogramEnabled( true );
1258 getCurrentTreePanel().getControlPanel().setDrawPhylogramEnabled( false );
1260 getCurrentTreePanel().setPhylogenyGraphicsType( getOptions().getPhylogenyGraphicsType() );
1261 MainFrame.updateScreenTextAntialias( getMainPanel().getTreePanels() );
1265 void updateOptions( final Options options ) {
1266 options.setAntialiasScreen( ( _screen_antialias_cbmi != null ) && _screen_antialias_cbmi.isSelected() );
1267 options.setBackgroundColorGradient( ( _background_gradient_cbmi != null )
1268 && _background_gradient_cbmi.isSelected() );
1269 options.setShowDomainLabels( ( _show_domain_labels != null ) && _show_domain_labels.isSelected() );
1270 options.setAbbreviateScientificTaxonNames( ( _abbreviate_scientific_names != null )
1271 && _abbreviate_scientific_names.isSelected() );
1272 options.setColorLabelsSameAsParentBranch( ( _color_labels_same_as_parent_branch != null )
1273 && _color_labels_same_as_parent_branch.isSelected() );
1274 options.setShowDefaultNodeShapesInternal( ( _show_default_node_shapes_internal_cbmi != null )
1275 && _show_default_node_shapes_internal_cbmi.isSelected() );
1276 options.setShowDefaultNodeShapesExternal( ( _show_default_node_shapes_external_cbmi != null )
1277 && _show_default_node_shapes_external_cbmi.isSelected() );
1278 options.setTaxonomyColorizeNodeShapes( ( _taxonomy_colorize_node_shapes_cbmi != null )
1279 && _taxonomy_colorize_node_shapes_cbmi.isSelected() );
1280 if ( ( _non_lined_up_cladograms_rbmi != null ) && ( _non_lined_up_cladograms_rbmi.isSelected() ) ) {
1281 options.setCladogramType( CLADOGRAM_TYPE.NON_LINED_UP );
1283 else if ( ( _uniform_cladograms_rbmi != null ) && ( _uniform_cladograms_rbmi.isSelected() ) ) {
1284 options.setCladogramType( CLADOGRAM_TYPE.TOTAL_NODE_SUM_DEP );
1286 else if ( ( _ext_node_dependent_cladogram_rbmi != null ) && ( _ext_node_dependent_cladogram_rbmi.isSelected() ) ) {
1287 options.setCladogramType( CLADOGRAM_TYPE.EXT_NODE_SUM_DEP );
1289 options.setSearchCaseSensitive( ( _search_case_senstive_cbmi != null )
1290 && _search_case_senstive_cbmi.isSelected() );
1291 if ( ( _show_scale_cbmi != null ) && _show_scale_cbmi.isEnabled() ) {
1292 options.setShowScale( _show_scale_cbmi.isSelected() );
1294 if ( _label_direction_cbmi != null ) {
1295 if ( _label_direction_cbmi.isSelected() ) {
1296 options.setNodeLabelDirection( NODE_LABEL_DIRECTION.RADIAL );
1299 options.setNodeLabelDirection( NODE_LABEL_DIRECTION.HORIZONTAL );
1302 options.setShowOverview( ( _show_overview_cbmi != null ) && _show_overview_cbmi.isSelected() );
1303 options.setShowConfidenceStddev( ( _show_confidence_stddev_cbmi != null )
1304 && _show_confidence_stddev_cbmi.isSelected() );
1305 if ( ( _show_branch_length_values_cbmi != null ) && _show_branch_length_values_cbmi.isEnabled() ) {
1306 options.setShowBranchLengthValues( _show_branch_length_values_cbmi.isSelected() );
1308 options.setMatchWholeTermsOnly( ( _search_whole_words_only_cbmi != null )
1309 && _search_whole_words_only_cbmi.isSelected() );
1310 options.setInverseSearchResult( ( _inverse_search_result_cbmi != null )
1311 && _inverse_search_result_cbmi.isSelected() );
1312 if ( ( _rectangular_type_cbmi != null ) && _rectangular_type_cbmi.isSelected() ) {
1313 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR );
1315 else if ( ( _triangular_type_cbmi != null ) && _triangular_type_cbmi.isSelected() ) {
1316 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.TRIANGULAR );
1318 else if ( ( _curved_type_cbmi != null ) && _curved_type_cbmi.isSelected() ) {
1319 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CURVED );
1321 else if ( ( _convex_type_cbmi != null ) && _convex_type_cbmi.isSelected() ) {
1322 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CONVEX );
1324 else if ( ( _euro_type_cbmi != null ) && _euro_type_cbmi.isSelected() ) {
1325 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE );
1327 else if ( ( _rounded_type_cbmi != null ) && _rounded_type_cbmi.isSelected() ) {
1328 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.ROUNDED );
1330 else if ( ( _unrooted_type_cbmi != null ) && _unrooted_type_cbmi.isSelected() ) {
1331 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.UNROOTED );
1333 else if ( ( _circular_type_cbmi != null ) && _circular_type_cbmi.isSelected() ) {
1334 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CIRCULAR );
1338 void updateTypeCheckboxes( final Options options, final Object o ) {
1339 setTypeMenuToAllUnselected();
1340 ( ( JCheckBoxMenuItem ) o ).setSelected( true );
1343 void viewAsNexus() {
1344 if ( ( getMainPanel().getCurrentPhylogeny() != null ) && !getMainPanel().getCurrentPhylogeny().isEmpty() ) {
1345 String title = "Nexus";
1346 if ( !ForesterUtil.isEmpty( getMainPanel().getCurrentPhylogeny().getName() ) ) {
1347 title = getMainPanel().getCurrentPhylogeny().getName() + " " + title;
1349 showTextFrame( getMainPanel().getCurrentPhylogeny().toNexus( getOptions()
1350 .getNhConversionSupportValueStyle() ),
1356 if ( ( getMainPanel().getCurrentPhylogeny() != null ) && !getMainPanel().getCurrentPhylogeny().isEmpty() ) {
1357 String title = "New Hampshire";
1358 if ( !ForesterUtil.isEmpty( getMainPanel().getCurrentPhylogeny().getName() ) ) {
1359 title = getMainPanel().getCurrentPhylogeny().getName() + " " + title;
1361 showTextFrame( getMainPanel().getCurrentPhylogeny()
1362 .toNewHampshire( false, getOptions().getNhConversionSupportValueStyle() ),
1368 if ( ( getMainPanel().getCurrentPhylogeny() != null ) && !getMainPanel().getCurrentPhylogeny().isEmpty() ) {
1369 String title = "phyloXML";
1370 if ( !ForesterUtil.isEmpty( getMainPanel().getCurrentPhylogeny().getName() ) ) {
1371 title = getMainPanel().getCurrentPhylogeny().getName() + " " + title;
1373 showTextFrame( getMainPanel().getCurrentPhylogeny().toPhyloXML( 0 ), title );
1377 private void chooseFont() {
1378 final FontChooser fc = new FontChooser();
1379 fc.setFont( getMainPanel().getTreeFontSet().getLargeFont() );
1380 fc.showDialog( this, "Select the Base Font" );
1381 getMainPanel().getTreeFontSet().setBaseFont( fc.getFont() );
1384 private void chooseMinimalConfidence() {
1385 final String s = ( String ) JOptionPane
1386 .showInputDialog( this,
1387 "Please the minimum for confidence values to be displayed.\n" + "[current value: "
1388 + getOptions().getMinConfidenceValue() + "]\n",
1389 "Minimal Confidence Value",
1390 JOptionPane.QUESTION_MESSAGE,
1393 getOptions().getMinConfidenceValue() );
1394 if ( !ForesterUtil.isEmpty( s ) ) {
1395 boolean success = true;
1397 final String m_str = s.trim();
1398 if ( !ForesterUtil.isEmpty( m_str ) ) {
1400 m = Double.parseDouble( m_str );
1402 catch ( final Exception ex ) {
1409 if ( success && ( m >= 0.0 ) ) {
1410 getOptions().setMinConfidenceValue( m );
1415 private void customizeRadioButtonMenuItem( final JRadioButtonMenuItem item, final boolean is_selected ) {
1416 if ( item != null ) {
1417 item.setFont( MainFrame.menu_font );
1418 if ( !getConfiguration().isUseNativeUI() ) {
1419 item.setBackground( getConfiguration().getGuiMenuBackgroundColor() );
1420 item.setForeground( getConfiguration().getGuiMenuTextColor() );
1422 item.setSelected( is_selected );
1423 item.addActionListener( this );
1427 private MainPanel getMainPanel() {
1431 private Phylogeny getSpeciesTree() {
1432 return _species_tree;
1435 private boolean isScreenAntialias() {
1439 private void removeBranchColors() {
1440 if ( getMainPanel().getCurrentPhylogeny() != null ) {
1441 AptxUtil.removeBranchColors( getMainPanel().getCurrentPhylogeny() );
1445 private void setMainPanel( final MainPanelApplets main_panel ) {
1446 _mainpanel = main_panel;
1449 private void setSpeciesTree( final Phylogeny species_tree ) {
1450 _species_tree = species_tree;
1453 private void setupUI() {
1455 if ( getConfiguration().isUseNativeUI() ) {
1456 UIManager.setLookAndFeel( UIManager.getSystemLookAndFeelClassName() );
1459 UIManager.setLookAndFeel( UIManager.getCrossPlatformLookAndFeelClassName() );
1462 catch ( final UnsupportedLookAndFeelException e ) {
1463 AptxUtil.dieWithSystemError( "UnsupportedLookAndFeelException: " + e.toString() );
1465 catch ( final ClassNotFoundException e ) {
1466 AptxUtil.dieWithSystemError( "ClassNotFoundException: " + e.toString() );
1468 catch ( final InstantiationException e ) {
1469 AptxUtil.dieWithSystemError( "InstantiationException: " + e.toString() );
1471 catch ( final IllegalAccessException e ) {
1472 AptxUtil.dieWithSystemError( "IllegalAccessException: " + e.toString() );
1474 catch ( final Exception e ) {
1475 AptxUtil.dieWithSystemError( e.toString() );
1479 static void setupScreenTextAntialias( final List<TreePanel> treepanels, final boolean antialias ) {
1480 for( final TreePanel tree_panel : treepanels ) {
1481 tree_panel.setTextAntialias();