2 package org.forester.archaeopteryx;
4 import java.awt.BorderLayout;
5 import java.awt.Container;
6 import java.awt.event.ActionEvent;
7 import java.awt.event.ActionListener;
8 import java.awt.event.ComponentAdapter;
9 import java.awt.event.ComponentEvent;
10 import java.io.ByteArrayOutputStream;
12 import java.io.IOException;
14 import java.util.LinkedList;
15 import java.util.List;
16 import java.util.NoSuchElementException;
18 import javax.swing.ButtonGroup;
19 import javax.swing.JApplet;
20 import javax.swing.JCheckBoxMenuItem;
21 import javax.swing.JMenu;
22 import javax.swing.JMenuBar;
23 import javax.swing.JMenuItem;
24 import javax.swing.JOptionPane;
25 import javax.swing.JRadioButtonMenuItem;
26 import javax.swing.UIManager;
27 import javax.swing.UnsupportedLookAndFeelException;
28 import javax.swing.event.ChangeEvent;
29 import javax.swing.event.ChangeListener;
31 import org.apache.commons.codec.binary.Base64;
32 import org.forester.archaeopteryx.AptxUtil.GraphicsExportType;
33 import org.forester.archaeopteryx.Options.CLADOGRAM_TYPE;
34 import org.forester.archaeopteryx.Options.NODE_LABEL_DIRECTION;
35 import org.forester.archaeopteryx.Options.PHYLOGENY_GRAPHICS_TYPE;
36 import org.forester.io.parsers.nhx.NHXParser.TAXONOMY_EXTRACTION;
37 import org.forester.phylogeny.Phylogeny;
38 import org.forester.phylogeny.PhylogenyMethods;
39 import org.forester.phylogeny.PhylogenyMethods.DESCENDANT_SORT_PRIORITY;
40 import org.forester.phylogeny.data.SequenceRelation;
41 import org.forester.sdi.GSDI;
42 import org.forester.sdi.GSDIR;
43 import org.forester.sdi.SDIException;
44 import org.forester.util.ForesterConstants;
45 import org.forester.util.ForesterUtil;
48 // <applet archive="forester.jar"
49 // code="org.forester.archaeopteryx.ArchaeopteryxE.class"
50 // codebase="http://www.myserver.org/path/to/forester"
53 // alt="ArchaeopteryxE is not working on your system (requires at least Sun Java 1.5)!">
54 // <param name="url_of_tree_to_load"
55 // value="http://www.myserver.org/examples/data/apaf.xml">
56 // <param name="config_file"
57 // value="http://www.myserver.org/examples/config/config_file.txt">
59 public class ArchaeopteryxE extends JApplet implements ActionListener {
61 private final static String NAME = "ArchaeopteryxE";
62 private static final long serialVersionUID = -1220055577935759443L;
63 private Configuration _configuration;
64 private MainPanelApplets _mainpanel;
65 private JMenuBar _jmenubar;
66 private JMenu _options_jmenu;
67 private JMenu _font_size_menu;
68 private JMenuItem _super_tiny_fonts_mi;
69 private JMenuItem _tiny_fonts_mi;
70 private JMenuItem _small_fonts_mi;
71 private JMenuItem _medium_fonts_mi;
72 private JMenuItem _large_fonts_mi;
73 private JMenu _tools_menu;
74 private JMenuItem _taxcolor_item;
75 private JMenuItem _confcolor_item;
76 private JMenuItem _midpoint_root_item;
77 private JMenu _view_jmenu;
78 private JMenuItem _view_as_XML_item;
79 private JMenuItem _view_as_NH_item;
80 private JMenuItem _view_as_nexus_item;
81 private JMenuItem _display_basic_information_item;
82 private JMenu _type_menu;
83 private JCheckBoxMenuItem _rectangular_type_cbmi;
84 private JCheckBoxMenuItem _triangular_type_cbmi;
85 private JCheckBoxMenuItem _curved_type_cbmi;
86 private JCheckBoxMenuItem _convex_type_cbmi;
87 private JCheckBoxMenuItem _euro_type_cbmi;
88 private JCheckBoxMenuItem _rounded_type_cbmi;
89 private JCheckBoxMenuItem _unrooted_type_cbmi;
90 private JCheckBoxMenuItem _circular_type_cbmi;
91 private JMenuItem _help_item;
92 private JMenuItem _about_item;
93 private JMenu _help_jmenu;
94 private JMenuItem _website_item;
95 private JMenuItem _phyloxml_website_item;
96 private JMenuItem _phyloxml_ref_item;
97 private JMenuItem _aptx_ref_item;
98 private JMenuItem _remove_branch_color_item;
99 private JCheckBoxMenuItem _show_domain_labels;
100 private JCheckBoxMenuItem _show_annotation_ref_source;
101 private JCheckBoxMenuItem _color_labels_same_as_parent_branch;
102 private JCheckBoxMenuItem _abbreviate_scientific_names;
103 private JCheckBoxMenuItem _screen_antialias_cbmi;
104 private JCheckBoxMenuItem _background_gradient_cbmi;
105 private JRadioButtonMenuItem _non_lined_up_cladograms_rbmi;
106 private JRadioButtonMenuItem _uniform_cladograms_rbmi;
107 private JRadioButtonMenuItem _ext_node_dependent_cladogram_rbmi;
108 private Options _options;
109 private JMenuItem _choose_font_mi;
110 private JMenuItem _switch_colors_mi;
111 JCheckBoxMenuItem _label_direction_cbmi;
112 private JCheckBoxMenuItem _show_scale_cbmi;
113 private JCheckBoxMenuItem _search_case_senstive_cbmi;
114 private JCheckBoxMenuItem _search_whole_words_only_cbmi;
115 private JCheckBoxMenuItem _inverse_search_result_cbmi;
116 private JCheckBoxMenuItem _show_overview_cbmi;
117 private JMenuItem _choose_minimal_confidence_mi;
118 private JCheckBoxMenuItem _show_branch_length_values_cbmi;
119 private JMenuItem _collapse_species_specific_subtrees;
120 private JMenuItem _overview_placment_mi;
121 private ButtonGroup _radio_group_1;
122 private JCheckBoxMenuItem _show_default_node_shapes_internal_cbmi;
123 private JCheckBoxMenuItem _show_default_node_shapes_external_cbmi;
124 private JMenuItem _cycle_node_shape_mi;
125 private JMenuItem _cycle_node_fill_mi;
126 private JMenuItem _choose_node_size_mi;
127 private JCheckBoxMenuItem _taxonomy_colorize_node_shapes_cbmi;
128 private JCheckBoxMenuItem _show_confidence_stddev_cbmi;
129 private final LinkedList<TextFrame> _textframes = new LinkedList<TextFrame>();
130 private JMenu _analysis_menu;
131 private JMenuItem _gsdi_item;
132 private JMenuItem _gsdir_item;
133 private Phylogeny _species_tree;
136 public void actionPerformed( final ActionEvent e ) {
137 final Object o = e.getSource();
138 if ( o == _midpoint_root_item ) {
139 getMainPanel().getCurrentTreePanel().midpointRoot();
141 else if ( o == _gsdi_item ) {
142 if ( isSubtreeDisplayed() ) {
147 else if ( o == _gsdir_item ) {
148 if ( isSubtreeDisplayed() ) {
153 else if ( o == _taxcolor_item ) {
154 getMainPanel().getCurrentTreePanel().taxColor();
156 else if ( o == _confcolor_item ) {
157 getMainPanel().getCurrentTreePanel().confColor();
159 else if ( o == _collapse_species_specific_subtrees ) {
160 if ( getCurrentTreePanel() != null ) {
161 getCurrentTreePanel().collapseSpeciesSpecificSubtrees();
164 else if ( o == _remove_branch_color_item ) {
165 removeBranchColors();
167 else if ( o == _switch_colors_mi ) {
170 else if ( o == _display_basic_information_item ) {
171 displayBasicInformation();
173 else if ( o == _view_as_NH_item ) {
176 else if ( o == _view_as_XML_item ) {
179 else if ( o == _view_as_nexus_item ) {
182 else if ( o == _super_tiny_fonts_mi ) {
183 if ( getCurrentTreePanel() != null ) {
184 getCurrentTreePanel().setSuperTinyFonts();
185 getCurrentTreePanel().repaint();
188 else if ( o == _tiny_fonts_mi ) {
189 if ( getCurrentTreePanel() != null ) {
190 getCurrentTreePanel().setTinyFonts();
191 getCurrentTreePanel().repaint();
194 else if ( o == _small_fonts_mi ) {
195 if ( getCurrentTreePanel() != null ) {
196 getCurrentTreePanel().setSmallFonts();
197 getCurrentTreePanel().repaint();
200 else if ( o == _medium_fonts_mi ) {
201 if ( getCurrentTreePanel() != null ) {
202 getCurrentTreePanel().setMediumFonts();
203 getCurrentTreePanel().repaint();
206 else if ( o == _large_fonts_mi ) {
207 if ( getCurrentTreePanel() != null ) {
208 getCurrentTreePanel().setLargeFonts();
209 getCurrentTreePanel().repaint();
212 else if ( o == _choose_font_mi ) {
215 else if ( o == _choose_minimal_confidence_mi ) {
216 chooseMinimalConfidence();
218 else if ( o == _choose_node_size_mi ) {
219 MainFrame.chooseNodeSize( getOptions(), this );
221 else if ( o == _overview_placment_mi ) {
222 MainFrame.cycleOverview( getOptions(), getCurrentTreePanel() );
224 else if ( o == _cycle_node_fill_mi ) {
225 MainFrame.cycleNodeFill( getOptions(), getCurrentTreePanel() );
227 else if ( o == _cycle_node_shape_mi ) {
228 MainFrame.cycleNodeShape( getOptions(), getCurrentTreePanel() );
230 else if ( o == _non_lined_up_cladograms_rbmi ) {
231 updateOptions( getOptions() );
232 _mainpanel.getControlPanel().showWhole();
234 else if ( o == _uniform_cladograms_rbmi ) {
235 updateOptions( getOptions() );
236 _mainpanel.getControlPanel().showWhole();
238 else if ( o == _ext_node_dependent_cladogram_rbmi ) {
239 updateOptions( getOptions() );
240 _mainpanel.getControlPanel().showWhole();
242 else if ( o == _search_case_senstive_cbmi ) {
243 updateOptions( getOptions() );
244 getMainPanel().getControlPanel().search();
246 else if ( o == _search_whole_words_only_cbmi ) {
247 updateOptions( getOptions() );
248 getMainPanel().getControlPanel().search();
250 else if ( o == _inverse_search_result_cbmi ) {
251 updateOptions( getOptions() );
252 getMainPanel().getControlPanel().search();
254 else if ( o == _show_scale_cbmi ) {
255 updateOptions( getOptions() );
257 else if ( o == _show_branch_length_values_cbmi ) {
258 updateOptions( getOptions() );
260 else if ( o == _show_confidence_stddev_cbmi ) {
261 updateOptions( getOptions() );
263 else if ( o == _label_direction_cbmi ) {
264 updateOptions( getOptions() );
266 else if ( o == _abbreviate_scientific_names ) {
267 updateOptions( getOptions() );
269 else if ( o == _show_overview_cbmi ) {
270 updateOptions( getOptions() );
271 if ( getCurrentTreePanel() != null ) {
272 getCurrentTreePanel().updateOvSizes();
275 else if ( ( o == _rectangular_type_cbmi ) || ( o == _triangular_type_cbmi ) || ( o == _curved_type_cbmi )
276 || ( o == _convex_type_cbmi ) || ( o == _rounded_type_cbmi ) || ( o == _euro_type_cbmi )
277 || ( o == _unrooted_type_cbmi ) || ( o == _circular_type_cbmi ) ) {
280 else if ( o == _screen_antialias_cbmi ) {
281 updateOptions( getOptions() );
282 setupScreenTextAntialias( getMainPanel().getTreePanels(), isScreenAntialias() );
284 else if ( o == _background_gradient_cbmi ) {
285 updateOptions( getOptions() );
287 else if ( o == _show_domain_labels ) {
288 updateOptions( getOptions() );
290 else if ( o == _color_labels_same_as_parent_branch ) {
291 updateOptions( getOptions() );
293 else if ( o == _show_default_node_shapes_internal_cbmi ) {
294 updateOptions( getOptions() );
296 else if ( o == _show_default_node_shapes_external_cbmi ) {
297 updateOptions( getOptions() );
299 else if ( o == _taxonomy_colorize_node_shapes_cbmi ) {
300 updateOptions( getOptions() );
302 else if ( o == _about_item ) {
305 else if ( o == _help_item ) {
308 else if ( o == _website_item ) {
310 AptxUtil.openWebsite( Constants.APTX_WEB_SITE, true, this );
312 catch ( final IOException e1 ) {
313 ForesterUtil.printErrorMessage( Constants.PRG_NAME, e1.toString() );
316 else if ( o == _phyloxml_website_item ) {
318 AptxUtil.openWebsite( Constants.PHYLOXML_WEB_SITE, true, this );
320 catch ( final IOException e1 ) {
321 ForesterUtil.printErrorMessage( Constants.PRG_NAME, e1.toString() );
324 else if ( o == _aptx_ref_item ) {
326 AptxUtil.openWebsite( Constants.APTX_REFERENCE_URL, true, this );
328 catch ( final IOException e1 ) {
329 ForesterUtil.printErrorMessage( Constants.PRG_NAME, e1.toString() );
332 else if ( o == _phyloxml_ref_item ) {
334 AptxUtil.openWebsite( Constants.PHYLOXML_REFERENCE_URL, true, this );
336 catch ( final IOException e1 ) {
337 ForesterUtil.printErrorMessage( Constants.PRG_NAME, e1.toString() );
344 public void destroy() {
345 AptxUtil.printAppletMessage( NAME, "going to be destroyed " );
346 removeAllTextFrames();
347 if ( getMainPanel() != null ) {
348 getMainPanel().terminate();
353 * This method returns the current external node data which
354 * has been selected by the user by clicking the "Return ..."
355 * menu item. This method is expected to be called from Javascript or
358 * @return current external node data as String
360 public String getCurrentExternalNodesDataBuffer() {
361 return getCurrentTreePanel().getCurrentExternalNodesDataBufferAsString();
364 public int getCurrentExternalNodesDataBufferChangeCounter() {
365 return getCurrentTreePanel().getCurrentExternalNodesDataBufferChangeCounter();
368 public int getCurrentExternalNodesDataBufferLength() {
369 return getCurrentTreePanel().getCurrentExternalNodesDataBufferAsString().length();
373 * This method returns the current phylogeny as a string in the chosen format
375 * @param format must be NH, NHX, NEXUS or PHYLOXML
376 * @return the phylogeny string
377 * @author Herve Menager
379 public String getCurrentPhylogeny( final String format ) {
380 removeAllTextFrames();
381 if ( ( getMainPanel().getCurrentPhylogeny() == null ) || getMainPanel().getCurrentPhylogeny().isEmpty()
382 || ( getMainPanel().getCurrentPhylogeny().getNumberOfExternalNodes() > 10000 ) ) {
385 switch ( ForesterConstants.PhylogeneticTreeFormats.valueOf( format ) ) {
387 return getMainPanel().getCurrentPhylogeny().toNewHampshire();
389 return getMainPanel().getCurrentPhylogeny().toNewHampshireX();
391 return getMainPanel().getCurrentPhylogeny().toNexus();
393 return getMainPanel().getCurrentPhylogeny().toPhyloXML( -1 );
401 * This method returns a view of the current phylogeny in a chosen
402 * graphics format, base64-encoded in a string so that in can be used
405 * @param format must be GraphicsExportType (gif, jpg, pdf, png, tif, bmp)
406 * @return the phylogeny string
407 * @author Herve Menager
409 public String getCurrentPhylogenyGraphicsAsBase64EncodedString( final String format ) {
410 final ByteArrayOutputStream baos = new ByteArrayOutputStream();
412 AptxUtil.writePhylogenyToGraphicsByteArrayOutputStream( baos,
413 _mainpanel.getWidth(),
414 _mainpanel.getHeight(),
415 getCurrentTreePanel(),
416 getCurrentTreePanel().getControlPanel(),
417 GraphicsExportType.valueOf( format ),
420 catch ( final IOException ioe ) {
421 ForesterUtil.printErrorMessage( NAME, ioe.toString() );
422 ioe.printStackTrace();
423 JOptionPane.showMessageDialog( this,
424 NAME + ": Failed to generate graphics: " + "\nException: " + ioe,
425 "Failed to generate graphics",
426 JOptionPane.ERROR_MESSAGE );
429 final byte[] bytes = baos.toByteArray();
430 final String dataImg = Base64.encodeBase64String( bytes );
434 public Options getOptions() {
440 final String config_filename = getParameter( Constants.APPLET_PARAM_NAME_FOR_CONFIG_FILE_URL );
441 AptxUtil.printAppletMessage( NAME, "URL for configuration file is: " + config_filename );
442 final Configuration configuration = new Configuration( config_filename, true, true, true );
443 setConfiguration( configuration );
444 setOptions( Options.createInstance( configuration ) );
447 Phylogeny[] phys = null;
448 final String tree_url_str = getParameter( Constants.APPLET_PARAM_NAME_FOR_URL_OF_TREE_TO_LOAD );
449 AptxUtil.printAppletMessage( NAME, "URL for phylogenies is " + tree_url_str );
450 // Get URL to tree file
451 if ( tree_url_str != null ) {
453 phys_url = new URL( tree_url_str );
455 catch ( final Exception e ) {
456 ForesterUtil.printErrorMessage( NAME, "error: " + e );
458 JOptionPane.showMessageDialog( this, NAME + ": Could not create URL from: \"" + tree_url_str
459 + "\"\nException: " + e, "Failed to create URL", JOptionPane.ERROR_MESSAGE );
462 // Load the tree from URL
463 if ( phys_url != null ) {
465 phys = AptxUtil.readPhylogeniesFromUrl( phys_url,
466 getConfiguration().isValidatePhyloXmlAgainstSchema(),
467 getConfiguration().isReplaceUnderscoresInNhParsing(),
468 getConfiguration().isInternalNumberAreConfidenceForNhParsing(),
469 getConfiguration().getTaxonomyExtraction(),
470 getConfiguration().isMidpointReroot() );
472 catch ( final Exception e ) {
473 ForesterUtil.printErrorMessage( NAME, e.toString() );
475 JOptionPane.showMessageDialog( this,
476 NAME + ": Failed to read phylogenies: " + "\nException: " + e,
477 "Failed to read phylogenies",
478 JOptionPane.ERROR_MESSAGE );
481 if ( ( phys == null ) || ( phys.length < 1 ) ) {
482 ForesterUtil.printErrorMessage( NAME, "phylogenies from [" + phys_url + "] are null or empty" );
483 JOptionPane.showMessageDialog( this,
484 NAME + ": phylogenies from [" + phys_url + "] are null or empty",
485 "Failed to read phylogenies",
486 JOptionPane.ERROR_MESSAGE );
490 AptxUtil.printAppletMessage( NAME, "loaded " + phys.length + " phylogenies from: " + phys_url );
493 final String species_tree_url_str = getParameter( Constants.APPLET_PARAM_NAME_FOR_URL_OF_SPECIES_TREE_TO_LOAD );
494 if ( !ForesterUtil.isEmpty( species_tree_url_str ) ) {
495 AptxUtil.printAppletMessage( NAME, "URL of species tree to load: \"" + species_tree_url_str + "\"" );
496 Phylogeny[] species_trees = null;
498 final URL species_tree_url = new URL( species_tree_url_str );
499 species_trees = AptxUtil.readPhylogeniesFromUrl( species_tree_url,
500 configuration.isValidatePhyloXmlAgainstSchema(),
501 configuration.isReplaceUnderscoresInNhParsing(),
503 TAXONOMY_EXTRACTION.NO,
506 catch ( final IOException e ) {
507 ForesterUtil.printErrorMessage( NAME, "could not read species tree from [" + species_tree_url_str
509 JOptionPane.showMessageDialog( this, NAME + ": could not read species tree from ["
510 + species_tree_url_str + "]", "Failed to read species tree", JOptionPane.ERROR_MESSAGE );
512 if ( ( species_trees != null ) && ( species_trees.length > 0 ) ) {
513 AptxUtil.printAppletMessage( NAME, "successfully read species tree" );
514 if ( species_trees[ 0 ].isEmpty() ) {
515 ForesterUtil.printErrorMessage( NAME, "species tree is empty" );
517 else if ( !species_trees[ 0 ].isRooted() ) {
518 ForesterUtil.printErrorMessage( NAME, "species tree is not rooted" );
521 setSpeciesTree( species_trees[ 0 ] );
522 AptxUtil.printAppletMessage( NAME, "species tree OK" );
528 setMainPanel( new MainPanelApplets( getConfiguration(), this ) );
529 _jmenubar = new JMenuBar();
530 if ( !getConfiguration().isHideControlPanelAndMenubar() ) {
531 if ( !getConfiguration().isUseNativeUI() ) {
532 _jmenubar.setBackground( getConfiguration().getGuiMenuBackgroundColor() );
534 if ( getSpeciesTree() != null ) {
543 setJMenuBar( _jmenubar );
545 final Container contentpane = getContentPane();
546 contentpane.setLayout( new BorderLayout() );
547 contentpane.add( getMainPanel(), BorderLayout.CENTER );
548 addComponentListener( new ComponentAdapter() {
551 public void componentResized( final ComponentEvent e ) {
552 if ( getMainPanel().getCurrentTreePanel() != null ) {
553 getMainPanel().getCurrentTreePanel().calcParametersForPainting( getMainPanel()
554 .getCurrentTreePanel()
557 .getCurrentTreePanel()
560 .isAllowFontSizeChange() );
564 if ( getConfiguration().isUseTabbedDisplay() ) {
565 AptxUtil.printAppletMessage( NAME, "using tabbed display" );
566 AptxUtil.addPhylogeniesToTabs( phys,
567 new File( phys_url.getFile() ).getName(),
573 AptxUtil.printAppletMessage( NAME, "not using tabbed display" );
574 if ( getSpeciesTree() != null ) {
575 AptxUtil.printAppletMessage( NAME,
576 "Warning: gsdi (gene duplication inference) only available tabbed display" );
578 AptxUtil.addPhylogenyToPanel( phys, getConfiguration(), getMainPanel() );
582 getMainPanel().getControlPanel().showWholeAll();
583 getMainPanel().getControlPanel().showWhole();
585 AptxUtil.printAppletMessage( NAME, "successfully initialized" );
587 getCurrentTreePanel().getControlPanel().getSequenceRelationTypeBox().removeAllItems();
588 for( final SequenceRelation.SEQUENCE_RELATION_TYPE type : getMainPanel().getCurrentPhylogeny()
589 .getRelevantSequenceRelationTypes() ) {
590 getCurrentTreePanel().getControlPanel().getSequenceRelationTypeBox().addItem( type );
592 final String default_relation = getParameter( Constants.APPLET_PARAM_NAME_FOR_DEFAULT_SEQUENCE_RELATION_TYPE );
593 if ( default_relation != null ) {
594 getCurrentTreePanel().getControlPanel().getSequenceRelationTypeBox().setSelectedItem( default_relation );
596 final String default_sequence = getParameter( Constants.APPLET_PARAM_NAME_FOR_DEFAULT_QUERY_SEQUENCE );
597 if ( default_sequence != null ) {
598 getCurrentTreePanel().getControlPanel().getSequenceRelationBox().setSelectedItem( default_sequence );
604 public void showTextFrame( final String s, final String title ) {
606 _textframes.addLast( TextFrame.instantiate( s, title, _textframes ) );
610 public void start() {
611 if ( getMainPanel() != null ) {
612 getMainPanel().validate();
615 requestFocusInWindow();
617 AptxUtil.printAppletMessage( NAME, "started" );
620 void buildAnalysisMenu() {
621 _analysis_menu = MainFrame.createMenu( "Analysis", getConfiguration() );
622 _analysis_menu.add( _gsdi_item = new JMenuItem( "GSDI (Generalized Speciation Duplication Inference)" ) );
623 _analysis_menu.add( _gsdir_item = new JMenuItem( "GSDIR (GSDI with re-rooting)" ) );
624 customizeJMenuItem( _gsdi_item );
625 customizeJMenuItem( _gsdir_item );
626 // _analysis_menu.addSeparator();
627 // _analysis_menu.add( _lineage_inference = new JMenuItem( INFER_ANCESTOR_TAXONOMIES ) );
628 // customizeJMenuItem( _lineage_inference );
629 // _lineage_inference.setToolTipText( "Inference of ancestor taxonomies/lineages" );
630 _jmenubar.add( _analysis_menu );
633 void buildFontSizeMenu() {
634 _font_size_menu = MainFrame.createMenu( MainFrame.FONT_SIZE_MENU_LABEL, getConfiguration() );
635 _font_size_menu.add( _super_tiny_fonts_mi = new JMenuItem( "Super tiny fonts" ) );
636 _font_size_menu.add( _tiny_fonts_mi = new JMenuItem( "Tiny fonts" ) );
637 _font_size_menu.add( _small_fonts_mi = new JMenuItem( "Small fonts" ) );
638 _font_size_menu.add( _medium_fonts_mi = new JMenuItem( "Medium fonts" ) );
639 _font_size_menu.add( _large_fonts_mi = new JMenuItem( "Large fonts" ) );
640 customizeJMenuItem( _super_tiny_fonts_mi );
641 customizeJMenuItem( _tiny_fonts_mi );
642 customizeJMenuItem( _small_fonts_mi );
643 customizeJMenuItem( _medium_fonts_mi );
644 customizeJMenuItem( _large_fonts_mi );
645 _jmenubar.add( _font_size_menu );
648 void buildHelpMenu() {
649 _help_jmenu = MainFrame.createMenu( "Help", getConfiguration() );
650 _help_jmenu.add( _help_item = new JMenuItem( "Help" ) );
651 _help_jmenu.add( _website_item = new JMenuItem( "Archaeopteryx Home" ) );
652 _aptx_ref_item = new JMenuItem( "Archaeopteryx Reference" );
653 _help_jmenu.add( _phyloxml_website_item = new JMenuItem( "phyloXML Home" ) );
654 _help_jmenu.add( _phyloxml_ref_item = new JMenuItem( "phyloXML Reference" ) );
655 _help_jmenu.addSeparator();
656 _help_jmenu.add( _about_item = new JMenuItem( "About" ) );
657 customizeJMenuItem( _help_item );
658 customizeJMenuItem( _website_item );
659 customizeJMenuItem( _phyloxml_website_item );
660 customizeJMenuItem( _aptx_ref_item );
661 customizeJMenuItem( _phyloxml_ref_item );
662 customizeJMenuItem( _about_item );
663 _phyloxml_ref_item.setToolTipText( MainFrame.PHYLOXML_REF_TOOL_TIP );
664 _aptx_ref_item.setToolTipText( MainFrame.APTX_REF_TOOL_TIP );
665 _jmenubar.add( _help_jmenu );
668 void buildOptionsMenu() {
669 _options_jmenu = MainFrame.createMenu( MainFrame.OPTIONS_HEADER, getConfiguration() );
670 _options_jmenu.addChangeListener( new ChangeListener() {
673 public void stateChanged( final ChangeEvent e ) {
674 MainFrame.setOvPlacementColorChooseMenuItem( _overview_placment_mi, getOptions() );
675 MainFrame.setTextColorChooseMenuItem( _switch_colors_mi, getCurrentTreePanel() );
677 .setTextMinSupportMenuItem( _choose_minimal_confidence_mi, getOptions(), getCurrentTreePanel() );
678 MainFrame.setTextForFontChooserMenuItem( _choose_font_mi, MainFrame
679 .createCurrentFontDesc( getMainPanel().getTreeFontSet() ) );
680 MainFrame.updateOptionsMenuDependingOnPhylogenyType( getMainPanel(),
682 _show_branch_length_values_cbmi,
683 _non_lined_up_cladograms_rbmi,
684 _uniform_cladograms_rbmi,
685 _ext_node_dependent_cladogram_rbmi,
686 _label_direction_cbmi );
687 MainFrame.setCycleNodeFillMenuItem( _cycle_node_fill_mi, getOptions() );
688 MainFrame.setCycleNodeShapeMenuItem( _cycle_node_shape_mi, getOptions() );
689 MainFrame.setTextNodeSizeMenuItem( _choose_node_size_mi, getOptions() );
692 _options_jmenu.add( MainFrame.customizeMenuItemAsLabel( new JMenuItem( MainFrame.DISPLAY_SUBHEADER ),
693 getConfiguration() ) );
695 .add( _ext_node_dependent_cladogram_rbmi = new JRadioButtonMenuItem( MainFrame.NONUNIFORM_CLADOGRAMS_LABEL ) );
696 _options_jmenu.add( _uniform_cladograms_rbmi = new JRadioButtonMenuItem( MainFrame.UNIFORM_CLADOGRAMS_LABEL ) );
698 .add( _non_lined_up_cladograms_rbmi = new JRadioButtonMenuItem( MainFrame.NON_LINED_UP_CLADOGRAMS_LABEL ) );
699 _radio_group_1 = new ButtonGroup();
700 _radio_group_1.add( _ext_node_dependent_cladogram_rbmi );
701 _radio_group_1.add( _uniform_cladograms_rbmi );
702 _radio_group_1.add( _non_lined_up_cladograms_rbmi );
703 _options_jmenu.add( _show_overview_cbmi = new JCheckBoxMenuItem( MainFrame.SHOW_OVERVIEW_LABEL ) );
704 _options_jmenu.add( _show_scale_cbmi = new JCheckBoxMenuItem( MainFrame.DISPLAY_SCALE_LABEL ) );
706 .add( _show_branch_length_values_cbmi = new JCheckBoxMenuItem( MainFrame.DISPLAY_BRANCH_LENGTH_VALUES_LABEL ) );
707 _options_jmenu.add( _show_confidence_stddev_cbmi = new JCheckBoxMenuItem( MainFrame.SHOW_CONF_STDDEV_LABEL ) );
709 .add( _show_default_node_shapes_internal_cbmi = new JCheckBoxMenuItem( MainFrame.DISPLAY_NODE_BOXES_LABEL_INT ) );
711 .add( _show_default_node_shapes_external_cbmi = new JCheckBoxMenuItem( MainFrame.DISPLAY_NODE_BOXES_LABEL_EXT ) );
713 .add( _taxonomy_colorize_node_shapes_cbmi = new JCheckBoxMenuItem( MainFrame.TAXONOMY_COLORIZE_NODE_SHAPES_LABEL ) );
714 _options_jmenu.add( _cycle_node_shape_mi = new JMenuItem( MainFrame.CYCLE_NODE_SHAPE_LABEL ) );
715 _options_jmenu.add( _cycle_node_fill_mi = new JMenuItem( MainFrame.CYCLE_NODE_FILL_LABEL ) );
716 _options_jmenu.add( _choose_node_size_mi = new JMenuItem( MainFrame.CHOOSE_NODE_SIZE_LABEL ) );
717 _options_jmenu.add( _label_direction_cbmi = new JCheckBoxMenuItem( MainFrame.LABEL_DIRECTION_LABEL ) );
719 .add( _color_labels_same_as_parent_branch = new JCheckBoxMenuItem( MainFrame.COLOR_LABELS_LABEL ) );
720 _color_labels_same_as_parent_branch.setToolTipText( MainFrame.COLOR_LABELS_TIP );
721 _options_jmenu.add( _abbreviate_scientific_names = new JCheckBoxMenuItem( MainFrame.ABBREV_SN_LABEL ) );
722 _label_direction_cbmi.setToolTipText( MainFrame.LABEL_DIRECTION_TIP );
723 _options_jmenu.add( _screen_antialias_cbmi = new JCheckBoxMenuItem( MainFrame.SCREEN_ANTIALIAS_LABEL ) );
724 _options_jmenu.add( _background_gradient_cbmi = new JCheckBoxMenuItem( MainFrame.BG_GRAD_LABEL ) );
725 if ( getConfiguration().doDisplayOption( Configuration.show_domain_architectures ) ) {
726 _options_jmenu.add( _show_domain_labels = new JCheckBoxMenuItem( MainFrame.SHOW_DOMAIN_LABELS_LABEL ) );
728 _options_jmenu.add( _choose_minimal_confidence_mi = new JMenuItem( "" ) );
729 _options_jmenu.add( _overview_placment_mi = new JMenuItem( "" ) );
730 _options_jmenu.add( _switch_colors_mi = new JMenuItem( "" ) );
731 _options_jmenu.add( _choose_font_mi = new JMenuItem( "" ) );
732 _options_jmenu.addSeparator();
733 _options_jmenu.add( MainFrame.customizeMenuItemAsLabel( new JMenuItem( MainFrame.SEARCH_SUBHEADER ),
734 getConfiguration() ) );
736 .add( _search_case_senstive_cbmi = new JCheckBoxMenuItem( MainFrame.SEARCH_CASE_SENSITIVE_LABEL ) );
737 _options_jmenu.add( _search_whole_words_only_cbmi = new JCheckBoxMenuItem( MainFrame.SEARCH_TERMS_ONLY_LABEL ) );
739 .add( _inverse_search_result_cbmi = new JCheckBoxMenuItem( MainFrame.INVERSE_SEARCH_RESULT_LABEL ) );
740 customizeJMenuItem( _choose_font_mi );
741 customizeJMenuItem( _choose_minimal_confidence_mi );
742 customizeJMenuItem( _switch_colors_mi );
743 customizeJMenuItem( _overview_placment_mi );
744 customizeCheckBoxMenuItem( _label_direction_cbmi,
745 getOptions().getNodeLabelDirection() == NODE_LABEL_DIRECTION.RADIAL );
746 customizeCheckBoxMenuItem( _screen_antialias_cbmi, getOptions().isAntialiasScreen() );
747 customizeCheckBoxMenuItem( _background_gradient_cbmi, getOptions().isBackgroundColorGradient() );
748 customizeCheckBoxMenuItem( _show_domain_labels, getOptions().isShowDomainLabels() );
749 customizeCheckBoxMenuItem( _show_annotation_ref_source, getOptions().isShowAnnotationRefSource() );
750 customizeCheckBoxMenuItem( _abbreviate_scientific_names, getOptions().isAbbreviateScientificTaxonNames() );
751 customizeCheckBoxMenuItem( _show_default_node_shapes_external_cbmi, getOptions()
752 .isShowDefaultNodeShapesExternal() );
753 customizeCheckBoxMenuItem( _show_default_node_shapes_internal_cbmi, getOptions()
754 .isShowDefaultNodeShapesInternal() );
755 customizeCheckBoxMenuItem( _taxonomy_colorize_node_shapes_cbmi, getOptions().isTaxonomyColorizeNodeShapes() );
756 customizeJMenuItem( _cycle_node_shape_mi );
757 customizeJMenuItem( _cycle_node_fill_mi );
758 customizeJMenuItem( _choose_node_size_mi );
759 customizeCheckBoxMenuItem( _color_labels_same_as_parent_branch, getOptions().isColorLabelsSameAsParentBranch() );
760 customizeCheckBoxMenuItem( _search_case_senstive_cbmi, getOptions().isSearchCaseSensitive() );
761 customizeCheckBoxMenuItem( _show_scale_cbmi, getOptions().isShowScale() );
762 customizeRadioButtonMenuItem( _non_lined_up_cladograms_rbmi,
763 getOptions().getCladogramType() == CLADOGRAM_TYPE.NON_LINED_UP );
764 customizeRadioButtonMenuItem( _uniform_cladograms_rbmi,
765 getOptions().getCladogramType() == CLADOGRAM_TYPE.TOTAL_NODE_SUM_DEP );
766 customizeRadioButtonMenuItem( _ext_node_dependent_cladogram_rbmi,
767 getOptions().getCladogramType() == CLADOGRAM_TYPE.EXT_NODE_SUM_DEP );
768 customizeCheckBoxMenuItem( _show_branch_length_values_cbmi, getOptions().isShowBranchLengthValues() );
769 customizeCheckBoxMenuItem( _show_overview_cbmi, getOptions().isShowOverview() );
770 customizeCheckBoxMenuItem( _search_whole_words_only_cbmi, getOptions().isMatchWholeTermsOnly() );
771 customizeCheckBoxMenuItem( _inverse_search_result_cbmi, getOptions().isInverseSearchResult() );
772 customizeCheckBoxMenuItem( _show_confidence_stddev_cbmi, getOptions().isShowConfidenceStddev() );
773 _jmenubar.add( _options_jmenu );
776 void buildToolsMenu() {
777 _tools_menu = MainFrame.createMenu( "Tools", getConfiguration() );
778 _tools_menu.add( _confcolor_item = new JMenuItem( "Colorize Branches Depending on Confidence" ) );
779 customizeJMenuItem( _confcolor_item );
780 _tools_menu.add( _taxcolor_item = new JMenuItem( "Taxonomy Colorize Branches" ) );
781 customizeJMenuItem( _taxcolor_item );
782 _tools_menu.add( _remove_branch_color_item = new JMenuItem( "Delete Branch Colors" ) );
783 _remove_branch_color_item.setToolTipText( "To delete branch color values from the current phylogeny." );
784 customizeJMenuItem( _remove_branch_color_item );
785 _tools_menu.addSeparator();
786 _tools_menu.add( _midpoint_root_item = new JMenuItem( "Midpoint-Root" ) );
787 customizeJMenuItem( _midpoint_root_item );
788 _tools_menu.addSeparator();
789 _tools_menu.add( _collapse_species_specific_subtrees = new JMenuItem( "Collapse Species-Specific Subtrees" ) );
790 customizeJMenuItem( _collapse_species_specific_subtrees );
791 _jmenubar.add( _tools_menu );
794 void buildTypeMenu() {
795 _type_menu = MainFrame.createMenu( MainFrame.TYPE_MENU_HEADER, getConfiguration() );
796 _type_menu.add( _rectangular_type_cbmi = new JCheckBoxMenuItem( MainFrame.RECTANGULAR_TYPE_CBMI_LABEL ) );
797 _type_menu.add( _euro_type_cbmi = new JCheckBoxMenuItem( MainFrame.EURO_TYPE_CBMI_LABEL ) );
798 _type_menu.add( _rounded_type_cbmi = new JCheckBoxMenuItem( MainFrame.ROUNDED_TYPE_CBMI_LABEL ) );
799 _type_menu.add( _curved_type_cbmi = new JCheckBoxMenuItem( MainFrame.CURVED_TYPE_CBMI_LABEL ) );
800 _type_menu.add( _triangular_type_cbmi = new JCheckBoxMenuItem( MainFrame.TRIANGULAR_TYPE_CBMI_LABEL ) );
801 _type_menu.add( _convex_type_cbmi = new JCheckBoxMenuItem( MainFrame.CONVEX_TYPE_CBMI_LABEL ) );
802 _type_menu.add( _unrooted_type_cbmi = new JCheckBoxMenuItem( MainFrame.UNROOTED_TYPE_CBMI_LABEL ) );
803 _type_menu.add( _circular_type_cbmi = new JCheckBoxMenuItem( MainFrame.CIRCULAR_TYPE_CBMI_LABEL ) );
804 customizeCheckBoxMenuItem( _rectangular_type_cbmi, false );
805 customizeCheckBoxMenuItem( _triangular_type_cbmi, false );
806 customizeCheckBoxMenuItem( _euro_type_cbmi, false );
807 customizeCheckBoxMenuItem( _rounded_type_cbmi, false );
808 customizeCheckBoxMenuItem( _curved_type_cbmi, false );
809 customizeCheckBoxMenuItem( _convex_type_cbmi, false );
810 customizeCheckBoxMenuItem( _unrooted_type_cbmi, false );
811 customizeCheckBoxMenuItem( _circular_type_cbmi, false );
812 _unrooted_type_cbmi.setToolTipText( MainFrame.USE_MOUSEWHEEL_SHIFT_TO_ROTATE );
813 _circular_type_cbmi.setToolTipText( MainFrame.USE_MOUSEWHEEL_SHIFT_TO_ROTATE );
814 initializeTypeMenu( getOptions() );
815 _jmenubar.add( _type_menu );
818 void buildViewMenu() {
819 _view_jmenu = MainFrame.createMenu( "View", getConfiguration() );
821 .add( _display_basic_information_item = new JMenuItem( MainFrame.SHOW_BASIC_TREE_INFORMATION_LABEL ) );
822 _view_jmenu.addSeparator();
823 _view_jmenu.add( _view_as_XML_item = new JMenuItem( "View as phyloXML" ) );
824 _view_jmenu.add( _view_as_NH_item = new JMenuItem( "View as Newick" ) );
825 _view_jmenu.add( _view_as_nexus_item = new JMenuItem( "View as Nexus" ) );
826 customizeJMenuItem( _display_basic_information_item );
827 customizeJMenuItem( _view_as_NH_item );
828 customizeJMenuItem( _view_as_XML_item );
829 customizeJMenuItem( _view_as_nexus_item );
830 _jmenubar.add( _view_jmenu );
833 void checkTextFrames() {
834 if ( _textframes.size() > 5 ) {
836 if ( _textframes.getFirst() != null ) {
837 _textframes.getFirst().removeMe();
840 _textframes.removeFirst();
843 catch ( final NoSuchElementException e ) {
849 void clearCurrentExternalNodesDataBuffer() {
850 getCurrentTreePanel().clearCurrentExternalNodesDataBuffer();
853 void customizeCheckBoxMenuItem( final JCheckBoxMenuItem item, final boolean is_selected ) {
854 if ( item != null ) {
855 item.setFont( MainFrame.menu_font );
856 if ( !getConfiguration().isUseNativeUI() ) {
857 item.setBackground( getConfiguration().getGuiMenuBackgroundColor() );
858 item.setForeground( getConfiguration().getGuiMenuTextColor() );
860 item.setSelected( is_selected );
861 item.addActionListener( this );
865 void customizeJMenuItem( final JMenuItem jmi ) {
866 jmi.setFont( MainFrame.menu_font );
867 if ( !getConfiguration().isUseNativeUI() ) {
868 jmi.setBackground( getConfiguration().getGuiMenuBackgroundColor() );
869 jmi.setForeground( getConfiguration().getGuiMenuTextColor() );
871 jmi.addActionListener( this );
874 void displayBasicInformation() {
875 if ( ( getMainPanel().getCurrentPhylogeny() != null ) && !getMainPanel().getCurrentPhylogeny().isEmpty() ) {
876 String title = "Basic Information";
877 if ( !ForesterUtil.isEmpty( getMainPanel().getCurrentPhylogeny().getName() ) ) {
878 title = getMainPanel().getCurrentPhylogeny().getName() + " " + title;
880 showTextFrame( AptxUtil.createBasicInformation( getMainPanel().getCurrentPhylogeny() ), title );
885 if ( !isOKforSDI( false, true ) ) {
888 if ( !_mainpanel.getCurrentPhylogeny().isRooted() ) {
889 JOptionPane.showMessageDialog( this,
890 "Gene tree is not rooted.",
891 "Cannot execute GSDI",
892 JOptionPane.ERROR_MESSAGE );
895 final Phylogeny gene_tree = _mainpanel.getCurrentPhylogeny().copy();
896 gene_tree.setAllNodesToNotCollapse();
897 gene_tree.recalculateNumberOfExternalDescendants( false );
899 final Phylogeny species_tree = _species_tree.copy();
901 gsdi = new GSDI( gene_tree, species_tree, false, true, true, true );
903 catch ( final SDIException e ) {
904 JOptionPane.showMessageDialog( this,
905 e.getLocalizedMessage(),
907 JOptionPane.ERROR_MESSAGE );
910 catch ( final Exception e ) {
911 AptxUtil.unexpectedException( e );
914 gene_tree.setRerootable( false );
915 gene_tree.clearHashIdToNodeMap();
916 gene_tree.recalculateNumberOfExternalDescendants( true );
917 _mainpanel.addPhylogenyInNewTab( gene_tree, getConfiguration(), "gene tree", null );
918 getMainPanel().getControlPanel().setShowEvents( true );
920 final int selected = _mainpanel.getTabbedPane().getSelectedIndex();
921 _mainpanel.addPhylogenyInNewTab( species_tree, getConfiguration(), "species tree", null );
923 _mainpanel.getTabbedPane().setSelectedIndex( selected );
925 _mainpanel.getCurrentTreePanel().setEdited( true );
926 final int poly = PhylogenyMethods.countNumberOfPolytomies( species_tree );
927 if ( gsdi.getStrippedExternalGeneTreeNodes().size() > 0 ) {
928 JOptionPane.showMessageDialog( this,
929 "Duplications: " + gsdi.getDuplicationsSum() + "\n"
930 + "Potential duplications: "
931 + gsdi.getSpeciationOrDuplicationEventsSum() + "\n"
932 + "Speciations: " + gsdi.getSpeciationsSum() + "\n"
933 + "Stripped gene tree nodes: "
934 + gsdi.getStrippedExternalGeneTreeNodes().size() + "\n"
935 + "Taxonomy linkage based on: " + gsdi.getTaxCompBase() + "\n"
936 + "Number of polytomies in species tree used: " + poly + "\n",
937 "GSDI successfully completed",
938 JOptionPane.WARNING_MESSAGE );
941 JOptionPane.showMessageDialog( this,
942 "Duplications: " + gsdi.getDuplicationsSum() + "\n"
943 + "Potential duplications: "
944 + gsdi.getSpeciationOrDuplicationEventsSum() + "\n"
945 + "Speciations: " + gsdi.getSpeciationsSum() + "\n"
946 + "Stripped gene tree nodes: "
947 + gsdi.getStrippedExternalGeneTreeNodes().size() + "\n"
948 + "Taxonomy linkage based on: " + gsdi.getTaxCompBase() + "\n"
949 + "Number of polytomies in species tree used: " + poly + "\n",
950 "GSDI successfully completed",
951 JOptionPane.INFORMATION_MESSAGE );
955 void executeGSDIR() {
956 if ( !isOKforSDI( false, false ) ) {
959 final int p = PhylogenyMethods.countNumberOfPolytomies( _mainpanel.getCurrentPhylogeny() );
961 && !( ( p == 1 ) && ( _mainpanel.getCurrentPhylogeny().getRoot().getNumberOfDescendants() == 3 ) ) ) {
962 JOptionPane.showMessageDialog( this,
963 "Gene tree is not completely binary",
964 "Cannot execute GSDI",
965 JOptionPane.ERROR_MESSAGE );
968 final Phylogeny gene_tree = _mainpanel.getCurrentPhylogeny().copy();
969 gene_tree.setAllNodesToNotCollapse();
970 gene_tree.recalculateNumberOfExternalDescendants( false );
972 final Phylogeny species_tree = _species_tree.copy();
974 gsdir = new GSDIR( gene_tree, species_tree, true, true, true );
976 catch ( final SDIException e ) {
977 JOptionPane.showMessageDialog( this,
978 e.getLocalizedMessage(),
979 "Error during GSDIR",
980 JOptionPane.ERROR_MESSAGE );
983 catch ( final Exception e ) {
984 AptxUtil.unexpectedException( e );
987 final Phylogeny result_gene_tree = gsdir.getMinDuplicationsSumGeneTree();
988 result_gene_tree.setRerootable( false );
989 result_gene_tree.clearHashIdToNodeMap();
990 result_gene_tree.recalculateNumberOfExternalDescendants( true );
991 PhylogenyMethods.orderAppearance( result_gene_tree.getRoot(), true, true, DESCENDANT_SORT_PRIORITY.NODE_NAME );
992 _mainpanel.addPhylogenyInNewTab( result_gene_tree, getConfiguration(), "gene tree", null );
993 getMainPanel().getControlPanel().setShowEvents( true );
995 final int selected = _mainpanel.getTabbedPane().getSelectedIndex();
996 _mainpanel.addPhylogenyInNewTab( species_tree, getConfiguration(), "species tree", null );
998 _mainpanel.getTabbedPane().setSelectedIndex( selected );
1000 _mainpanel.getCurrentTreePanel().setEdited( true );
1001 final int poly = PhylogenyMethods.countNumberOfPolytomies( species_tree );
1002 if ( gsdir.getStrippedExternalGeneTreeNodes().size() > 0 ) {
1003 JOptionPane.showMessageDialog( this,
1004 "Minimal duplications: " + gsdir.getMinDuplicationsSum() + "\n"
1005 + "Speciations: " + gsdir.getSpeciationsSum() + "\n"
1006 + "Stripped gene tree nodes: "
1007 + gsdir.getStrippedExternalGeneTreeNodes().size() + "\n"
1008 + "Taxonomy linkage based on: " + gsdir.getTaxCompBase() + "\n"
1009 + "Number of polytomies in species tree used: " + poly + "\n",
1010 "GSDIR successfully completed",
1011 JOptionPane.WARNING_MESSAGE );
1014 JOptionPane.showMessageDialog( this,
1015 "Minimal duplications: " + gsdir.getMinDuplicationsSum() + "\n"
1016 + "Speciations: " + gsdir.getSpeciationsSum() + "\n"
1017 + "Stripped gene tree nodes: "
1018 + gsdir.getStrippedExternalGeneTreeNodes().size() + "\n"
1019 + "Taxonomy linkage based on: " + gsdir.getTaxCompBase() + "\n"
1020 + "Number of polytomies in species tree used: " + poly + "\n",
1021 "GSDIR successfully completed",
1022 JOptionPane.INFORMATION_MESSAGE );
1026 Configuration getConfiguration() {
1027 return _configuration;
1030 TreePanel getCurrentTreePanel() {
1031 return getMainPanel().getCurrentTreePanel();
1034 JCheckBoxMenuItem getlabelDirectionCbmi() {
1035 return _label_direction_cbmi;
1038 Options getOtions() {
1043 final StringBuilder sb = new StringBuilder();
1044 sb.append( "Display options\n" );
1045 sb.append( "-------------------\n" );
1046 sb.append( "Use the checkboxes to select types of information to display on the tree.\n\n" );
1047 sb.append( "Clickable tree nodes\n" );
1048 sb.append( "--------------------\n" );
1049 sb.append( "Tree nodes can be clicked, the action is determined by the 'click on node to' menu\n" );
1050 sb.append( "or by right clicking:\n" );
1051 sb.append( "o Display Node Data -- display information for a node\n" );
1052 sb.append( "o Collapse/Uncollapse -- collapse and uncollapse subtree from clicked node\n" );
1053 sb.append( "o Root/Reroot -- change tree root to clicked node\n" );
1054 sb.append( "o Sub/Super Tree -- toggle between subtree from clicked node and whole tree\n" );
1055 sb.append( "o Swap Descendants -- switch descendant on either side of clicked node\n" );
1056 sb.append( "o Colorize Subtree -- color a subtree\n" );
1057 sb.append( "o Open Sequence Web -- launch a web browser to display sequence information\n" );
1058 sb.append( "o Open Taxonomy Web -- launch a web browser to display taxonomy information\n" );
1059 sb.append( "- there may be additional choices depending on this particular setup\n\n" );
1060 sb.append( "Right clicking on a node always displays the information of a node.\n\n" );
1061 sb.append( "Zooming\n" );
1062 sb.append( "---------\n" );
1063 sb.append( "The mouse wheel and the plus and minus keys control zooming.\n" );
1064 sb.append( "Mouse wheel+Ctrl changes the text size.\n" );
1065 sb.append( "Mouse wheel+Shift controls zooming in vertical direction only.\n" );
1066 sb.append( "Use the buttons on the control panel to zoom the tree in and out, horizontally or vertically.\n" );
1067 sb.append( "The entire tree can be fitted into the window by clicking the \"F\" button, or by pressing F, Delete, or Home.\n" );
1068 sb.append( "The up, down, left, and right keys can be used to move the visible part (if zoomed in).\n" );
1069 sb.append( "Up, down, left, and right+Shift can be used to control zooming horizontally and vertically.\n" );
1070 sb.append( "Plus and minus keys+Ctrl change the text size; F+Ctrl, Delete+Ctrl, or Home+Ctrl resets it.\n\n" );
1071 sb.append( "Quick tree manipulation:\n" );
1072 sb.append( "------------------------\n" );
1073 sb.append( "Order Subtrees -- order the tree by branch length\n" );
1074 sb.append( "Uncollapse All -- uncollapse any and all collapsed branches\n\n" );
1075 sb.append( "phyloXML\n" );
1076 sb.append( "-------------------\n" );
1077 sb.append( "Reference: " + Constants.PHYLOXML_REFERENCE + "\n" );
1078 sb.append( "Website: " + Constants.PHYLOXML_WEB_SITE + "\n" );
1079 sb.append( "Version: " + ForesterConstants.PHYLO_XML_VERSION + "\n" );
1081 sb.append( "For more information: http://www.phylosoft.org/archaeopteryx/\n" );
1082 sb.append( "Email: " + Constants.AUTHOR_EMAIL + "\n\n" );
1083 TextFrame.instantiate( sb.toString(), "Help", _textframes );
1086 void initializeTypeMenu( final Options options ) {
1087 setTypeMenuToAllUnselected();
1089 switch ( options.getPhylogenyGraphicsType() ) {
1091 _convex_type_cbmi.setSelected( true );
1094 _curved_type_cbmi.setSelected( true );
1097 _euro_type_cbmi.setSelected( true );
1100 _rounded_type_cbmi.setSelected( true );
1103 _triangular_type_cbmi.setSelected( true );
1106 _unrooted_type_cbmi.setSelected( true );
1109 _circular_type_cbmi.setSelected( true );
1112 _rectangular_type_cbmi.setSelected( true );
1116 catch ( final NullPointerException np ) {
1117 // In all likelihood, this is caused by menu-less display.
1121 boolean isOKforSDI( final boolean species_tree_has_to_binary, final boolean gene_tree_has_to_binary ) {
1122 if ( ( _mainpanel.getCurrentPhylogeny() == null ) || _mainpanel.getCurrentPhylogeny().isEmpty() ) {
1125 else if ( ( _species_tree == null ) || _species_tree.isEmpty() ) {
1126 JOptionPane.showMessageDialog( this,
1127 "No species tree loaded",
1128 "Cannot execute GSDI",
1129 JOptionPane.ERROR_MESSAGE );
1132 else if ( species_tree_has_to_binary && !_species_tree.isCompletelyBinary() ) {
1133 JOptionPane.showMessageDialog( this,
1134 "Species tree is not completely binary",
1135 "Cannot execute GSDI",
1136 JOptionPane.ERROR_MESSAGE );
1139 else if ( gene_tree_has_to_binary && !_mainpanel.getCurrentPhylogeny().isCompletelyBinary() ) {
1140 JOptionPane.showMessageDialog( this,
1141 "Gene tree is not completely binary",
1142 "Cannot execute GSDI",
1143 JOptionPane.ERROR_MESSAGE );
1151 boolean isSubtreeDisplayed() {
1152 if ( getCurrentTreePanel() != null ) {
1153 if ( getCurrentTreePanel().isCurrentTreeIsSubtree() ) {
1155 .showMessageDialog( this,
1156 "This operation can only be performed on a complete tree, not on the currently displayed sub-tree only.",
1157 "Operation can not be exectuted on a sub-tree",
1158 JOptionPane.WARNING_MESSAGE );
1165 void removeAllTextFrames() {
1166 for( final TextFrame tf : _textframes ) {
1171 _textframes.clear();
1174 void setConfiguration( final Configuration configuration ) {
1175 _configuration = configuration;
1178 void setOptions( final Options options ) {
1182 void setSelectedTypeInTypeMenu( final PHYLOGENY_GRAPHICS_TYPE type ) {
1183 setTypeMenuToAllUnselected();
1187 _circular_type_cbmi.setSelected( true );
1190 _convex_type_cbmi.setSelected( true );
1193 _curved_type_cbmi.setSelected( true );
1196 _euro_type_cbmi.setSelected( true );
1199 _rounded_type_cbmi.setSelected( true );
1202 _rectangular_type_cbmi.setSelected( true );
1205 _triangular_type_cbmi.setSelected( true );
1208 _unrooted_type_cbmi.setSelected( true );
1211 throw new IllegalArgumentException( "unknown type: " + type );
1214 catch ( final NullPointerException np ) {
1215 // In all likelihood, this is caused by menu-less display.
1219 void setTypeMenuToAllUnselected() {
1220 if ( _convex_type_cbmi != null ) {
1221 _convex_type_cbmi.setSelected( false );
1223 if ( _curved_type_cbmi != null ) {
1224 _curved_type_cbmi.setSelected( false );
1226 if ( _euro_type_cbmi != null ) {
1227 _euro_type_cbmi.setSelected( false );
1229 if ( _rounded_type_cbmi != null ) {
1230 _rounded_type_cbmi.setSelected( false );
1232 if ( _triangular_type_cbmi != null ) {
1233 _triangular_type_cbmi.setSelected( false );
1235 if ( _rectangular_type_cbmi != null ) {
1236 _rectangular_type_cbmi.setSelected( false );
1238 if ( _unrooted_type_cbmi != null ) {
1239 _unrooted_type_cbmi.setSelected( false );
1241 if ( _circular_type_cbmi != null ) {
1242 _circular_type_cbmi.setSelected( false );
1247 _mainpanel.getControlPanel().showWhole();
1250 void switchColors() {
1251 final TreeColorSet colorset = getMainPanel().getCurrentTreePanel().getTreeColorSet();
1252 final ColorSchemeChooser csc = new ColorSchemeChooser( getMainPanel(), colorset );
1253 csc.setVisible( true );
1254 getMainPanel().setTreeColorSet( colorset );
1257 void typeChanged( final Object o ) {
1258 updateTypeCheckboxes( getOptions(), o );
1259 updateOptions( getOptions() );
1260 if ( getCurrentTreePanel() != null ) {
1261 final PHYLOGENY_GRAPHICS_TYPE previous_type = getCurrentTreePanel().getPhylogenyGraphicsType();
1262 final PHYLOGENY_GRAPHICS_TYPE new_type = getOptions().getPhylogenyGraphicsType();
1263 if ( ( ( previous_type == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) && ( new_type != PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) )
1264 || ( ( previous_type == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) && ( new_type != PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) )
1265 || ( ( previous_type != PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) && ( new_type == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) )
1266 || ( ( previous_type != PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) && ( new_type == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) ) ) {
1267 getCurrentTreePanel().getControlPanel().showWhole();
1269 if ( getCurrentTreePanel().isPhyHasBranchLengths() && ( new_type != PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) ) {
1270 getCurrentTreePanel().getControlPanel().setDrawPhylogramEnabled( true );
1273 getCurrentTreePanel().getControlPanel().setDrawPhylogramEnabled( false );
1275 getCurrentTreePanel().setPhylogenyGraphicsType( getOptions().getPhylogenyGraphicsType() );
1276 MainFrame.updateScreenTextAntialias( getMainPanel().getTreePanels() );
1280 void updateOptions( final Options options ) {
1281 options.setAntialiasScreen( ( _screen_antialias_cbmi != null ) && _screen_antialias_cbmi.isSelected() );
1282 options.setBackgroundColorGradient( ( _background_gradient_cbmi != null )
1283 && _background_gradient_cbmi.isSelected() );
1284 options.setShowDomainLabels( ( _show_domain_labels != null ) && _show_domain_labels.isSelected() );
1285 options.setShowAnnotationRefSource( ( _show_annotation_ref_source != null )
1286 && _show_annotation_ref_source.isSelected() );
1287 options.setAbbreviateScientificTaxonNames( ( _abbreviate_scientific_names != null )
1288 && _abbreviate_scientific_names.isSelected() );
1289 options.setColorLabelsSameAsParentBranch( ( _color_labels_same_as_parent_branch != null )
1290 && _color_labels_same_as_parent_branch.isSelected() );
1291 options.setShowDefaultNodeShapesInternal( ( _show_default_node_shapes_internal_cbmi != null )
1292 && _show_default_node_shapes_internal_cbmi.isSelected() );
1293 options.setShowDefaultNodeShapesExternal( ( _show_default_node_shapes_external_cbmi != null )
1294 && _show_default_node_shapes_external_cbmi.isSelected() );
1295 options.setTaxonomyColorizeNodeShapes( ( _taxonomy_colorize_node_shapes_cbmi != null )
1296 && _taxonomy_colorize_node_shapes_cbmi.isSelected() );
1297 if ( ( _non_lined_up_cladograms_rbmi != null ) && ( _non_lined_up_cladograms_rbmi.isSelected() ) ) {
1298 options.setCladogramType( CLADOGRAM_TYPE.NON_LINED_UP );
1300 else if ( ( _uniform_cladograms_rbmi != null ) && ( _uniform_cladograms_rbmi.isSelected() ) ) {
1301 options.setCladogramType( CLADOGRAM_TYPE.TOTAL_NODE_SUM_DEP );
1303 else if ( ( _ext_node_dependent_cladogram_rbmi != null ) && ( _ext_node_dependent_cladogram_rbmi.isSelected() ) ) {
1304 options.setCladogramType( CLADOGRAM_TYPE.EXT_NODE_SUM_DEP );
1306 options.setSearchCaseSensitive( ( _search_case_senstive_cbmi != null )
1307 && _search_case_senstive_cbmi.isSelected() );
1308 if ( ( _show_scale_cbmi != null ) && _show_scale_cbmi.isEnabled() ) {
1309 options.setShowScale( _show_scale_cbmi.isSelected() );
1311 if ( _label_direction_cbmi != null ) {
1312 if ( _label_direction_cbmi.isSelected() ) {
1313 options.setNodeLabelDirection( NODE_LABEL_DIRECTION.RADIAL );
1316 options.setNodeLabelDirection( NODE_LABEL_DIRECTION.HORIZONTAL );
1319 options.setShowOverview( ( _show_overview_cbmi != null ) && _show_overview_cbmi.isSelected() );
1320 options.setShowConfidenceStddev( ( _show_confidence_stddev_cbmi != null )
1321 && _show_confidence_stddev_cbmi.isSelected() );
1322 if ( ( _show_branch_length_values_cbmi != null ) && _show_branch_length_values_cbmi.isEnabled() ) {
1323 options.setShowBranchLengthValues( _show_branch_length_values_cbmi.isSelected() );
1325 options.setMatchWholeTermsOnly( ( _search_whole_words_only_cbmi != null )
1326 && _search_whole_words_only_cbmi.isSelected() );
1327 options.setInverseSearchResult( ( _inverse_search_result_cbmi != null )
1328 && _inverse_search_result_cbmi.isSelected() );
1329 if ( ( _rectangular_type_cbmi != null ) && _rectangular_type_cbmi.isSelected() ) {
1330 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR );
1332 else if ( ( _triangular_type_cbmi != null ) && _triangular_type_cbmi.isSelected() ) {
1333 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.TRIANGULAR );
1335 else if ( ( _curved_type_cbmi != null ) && _curved_type_cbmi.isSelected() ) {
1336 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CURVED );
1338 else if ( ( _convex_type_cbmi != null ) && _convex_type_cbmi.isSelected() ) {
1339 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CONVEX );
1341 else if ( ( _euro_type_cbmi != null ) && _euro_type_cbmi.isSelected() ) {
1342 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE );
1344 else if ( ( _rounded_type_cbmi != null ) && _rounded_type_cbmi.isSelected() ) {
1345 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.ROUNDED );
1347 else if ( ( _unrooted_type_cbmi != null ) && _unrooted_type_cbmi.isSelected() ) {
1348 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.UNROOTED );
1350 else if ( ( _circular_type_cbmi != null ) && _circular_type_cbmi.isSelected() ) {
1351 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CIRCULAR );
1355 void updateTypeCheckboxes( final Options options, final Object o ) {
1356 setTypeMenuToAllUnselected();
1357 ( ( JCheckBoxMenuItem ) o ).setSelected( true );
1360 void viewAsNexus() {
1361 if ( ( getMainPanel().getCurrentPhylogeny() != null ) && !getMainPanel().getCurrentPhylogeny().isEmpty() ) {
1362 String title = "Nexus";
1363 if ( !ForesterUtil.isEmpty( getMainPanel().getCurrentPhylogeny().getName() ) ) {
1364 title = getMainPanel().getCurrentPhylogeny().getName() + " " + title;
1366 showTextFrame( getMainPanel().getCurrentPhylogeny().toNexus( getOptions()
1367 .getNhConversionSupportValueStyle() ),
1373 if ( ( getMainPanel().getCurrentPhylogeny() != null ) && !getMainPanel().getCurrentPhylogeny().isEmpty() ) {
1374 String title = "New Hampshire";
1375 if ( !ForesterUtil.isEmpty( getMainPanel().getCurrentPhylogeny().getName() ) ) {
1376 title = getMainPanel().getCurrentPhylogeny().getName() + " " + title;
1378 showTextFrame( getMainPanel().getCurrentPhylogeny()
1379 .toNewHampshire( false, getOptions().getNhConversionSupportValueStyle() ),
1385 if ( ( getMainPanel().getCurrentPhylogeny() != null ) && !getMainPanel().getCurrentPhylogeny().isEmpty() ) {
1386 String title = "phyloXML";
1387 if ( !ForesterUtil.isEmpty( getMainPanel().getCurrentPhylogeny().getName() ) ) {
1388 title = getMainPanel().getCurrentPhylogeny().getName() + " " + title;
1390 showTextFrame( getMainPanel().getCurrentPhylogeny().toPhyloXML( 0 ), title );
1394 private void chooseFont() {
1395 final FontChooser fc = new FontChooser();
1396 fc.setFont( getMainPanel().getTreeFontSet().getLargeFont() );
1397 fc.showDialog( this, "Select the Base Font" );
1398 getMainPanel().getTreeFontSet().setBaseFont( fc.getFont() );
1401 private void chooseMinimalConfidence() {
1402 final String s = ( String ) JOptionPane
1403 .showInputDialog( this,
1404 "Please the minimum for confidence values to be displayed.\n" + "[current value: "
1405 + getOptions().getMinConfidenceValue() + "]\n",
1406 "Minimal Confidence Value",
1407 JOptionPane.QUESTION_MESSAGE,
1410 getOptions().getMinConfidenceValue() );
1411 if ( !ForesterUtil.isEmpty( s ) ) {
1412 boolean success = true;
1414 final String m_str = s.trim();
1415 if ( !ForesterUtil.isEmpty( m_str ) ) {
1417 m = Double.parseDouble( m_str );
1419 catch ( final Exception ex ) {
1426 if ( success && ( m >= 0.0 ) ) {
1427 getOptions().setMinConfidenceValue( m );
1432 private void customizeRadioButtonMenuItem( final JRadioButtonMenuItem item, final boolean is_selected ) {
1433 if ( item != null ) {
1434 item.setFont( MainFrame.menu_font );
1435 if ( !getConfiguration().isUseNativeUI() ) {
1436 item.setBackground( getConfiguration().getGuiMenuBackgroundColor() );
1437 item.setForeground( getConfiguration().getGuiMenuTextColor() );
1439 item.setSelected( is_selected );
1440 item.addActionListener( this );
1444 private MainPanel getMainPanel() {
1448 private Phylogeny getSpeciesTree() {
1449 return _species_tree;
1452 private boolean isScreenAntialias() {
1456 private void removeBranchColors() {
1457 if ( getMainPanel().getCurrentPhylogeny() != null ) {
1458 AptxUtil.removeBranchColors( getMainPanel().getCurrentPhylogeny() );
1462 private void setMainPanel( final MainPanelApplets main_panel ) {
1463 _mainpanel = main_panel;
1466 private void setSpeciesTree( final Phylogeny species_tree ) {
1467 _species_tree = species_tree;
1470 private void setupUI() {
1472 if ( getConfiguration().isUseNativeUI() ) {
1473 UIManager.setLookAndFeel( UIManager.getSystemLookAndFeelClassName() );
1476 UIManager.setLookAndFeel( UIManager.getCrossPlatformLookAndFeelClassName() );
1479 catch ( final UnsupportedLookAndFeelException e ) {
1480 AptxUtil.dieWithSystemError( "UnsupportedLookAndFeelException: " + e.toString() );
1482 catch ( final ClassNotFoundException e ) {
1483 AptxUtil.dieWithSystemError( "ClassNotFoundException: " + e.toString() );
1485 catch ( final InstantiationException e ) {
1486 AptxUtil.dieWithSystemError( "InstantiationException: " + e.toString() );
1488 catch ( final IllegalAccessException e ) {
1489 AptxUtil.dieWithSystemError( "IllegalAccessException: " + e.toString() );
1491 catch ( final Exception e ) {
1492 AptxUtil.dieWithSystemError( e.toString() );
1496 static void setupScreenTextAntialias( final List<TreePanel> treepanels, final boolean antialias ) {
1497 for( final TreePanel tree_panel : treepanels ) {
1498 tree_panel.setTextAntialias();