2 package org.forester.archaeopteryx;
4 import java.awt.BorderLayout;
5 import java.awt.Container;
7 import java.awt.event.ActionEvent;
8 import java.awt.event.ActionListener;
9 import java.awt.event.ComponentAdapter;
10 import java.awt.event.ComponentEvent;
11 import java.io.ByteArrayOutputStream;
13 import java.io.IOException;
15 import java.util.LinkedList;
16 import java.util.List;
17 import java.util.NoSuchElementException;
19 import javax.swing.ButtonGroup;
20 import javax.swing.JApplet;
21 import javax.swing.JCheckBoxMenuItem;
22 import javax.swing.JFileChooser;
23 import javax.swing.JMenu;
24 import javax.swing.JMenuBar;
25 import javax.swing.JMenuItem;
26 import javax.swing.JOptionPane;
27 import javax.swing.JRadioButtonMenuItem;
28 import javax.swing.UIManager;
29 import javax.swing.UnsupportedLookAndFeelException;
30 import javax.swing.event.ChangeEvent;
31 import javax.swing.event.ChangeListener;
33 import org.apache.commons.codec.binary.Base64;
34 import org.forester.archaeopteryx.AptxUtil.GraphicsExportType;
35 import org.forester.archaeopteryx.Options.CLADOGRAM_TYPE;
36 import org.forester.archaeopteryx.Options.NODE_LABEL_DIRECTION;
37 import org.forester.archaeopteryx.Options.PHYLOGENY_GRAPHICS_TYPE;
38 import org.forester.archaeopteryx.webservices.PhylogeniesWebserviceClient;
39 import org.forester.archaeopteryx.webservices.WebservicesManager;
40 import org.forester.io.parsers.nhx.NHXParser.TAXONOMY_EXTRACTION;
41 import org.forester.phylogeny.Phylogeny;
42 import org.forester.phylogeny.PhylogenyMethods;
43 import org.forester.phylogeny.PhylogenyMethods.DESCENDANT_SORT_PRIORITY;
44 import org.forester.phylogeny.data.SequenceRelation;
45 import org.forester.sdi.GSDI;
46 import org.forester.sdi.GSDIR;
47 import org.forester.sdi.SDIException;
48 import org.forester.util.ForesterConstants;
49 import org.forester.util.ForesterUtil;
52 // <applet archive="forester.jar"
53 // code="org.forester.archaeopteryx.ArchaeopteryxE.class"
54 // codebase="http://www.myserver.org/path/to/forester"
57 // alt="ArchaeopteryxE is not working on your system (requires at least Sun Java 1.5)!">
58 // <param name="url_of_tree_to_load"
59 // value="http://www.myserver.org/examples/data/apaf.xml">
60 // <param name="config_file"
61 // value="http://www.myserver.org/examples/config/config_file.txt">
63 public class ArchaeopteryxE extends JApplet implements ActionListener {
65 private final static String NAME = "ArchaeopteryxE";
66 private static final long serialVersionUID = -1220055577935759443L;
67 private Configuration _configuration;
68 private MainPanelApplets _mainpanel;
69 private JMenuBar _jmenubar;
70 private JMenu _options_jmenu;
71 private JMenu _font_size_menu;
72 private JMenuItem _super_tiny_fonts_mi;
73 private JMenuItem _tiny_fonts_mi;
74 private JMenuItem _small_fonts_mi;
75 private JMenuItem _medium_fonts_mi;
76 private JMenuItem _large_fonts_mi;
77 private JMenu _tools_menu;
78 private JMenuItem _taxcolor_item;
79 private JMenuItem _confcolor_item;
80 private JMenuItem _midpoint_root_item;
81 private JMenu _view_jmenu;
82 private JMenuItem _view_as_XML_item;
83 private JMenuItem _view_as_NH_item;
84 private JMenuItem _view_as_nexus_item;
85 private JMenuItem _display_basic_information_item;
86 private JMenu _type_menu;
87 private JCheckBoxMenuItem _rectangular_type_cbmi;
88 private JCheckBoxMenuItem _triangular_type_cbmi;
89 private JCheckBoxMenuItem _curved_type_cbmi;
90 private JCheckBoxMenuItem _convex_type_cbmi;
91 private JCheckBoxMenuItem _euro_type_cbmi;
92 private JCheckBoxMenuItem _rounded_type_cbmi;
93 private JCheckBoxMenuItem _unrooted_type_cbmi;
94 private JCheckBoxMenuItem _circular_type_cbmi;
95 private JMenuItem _help_item;
96 private JMenuItem _about_item;
97 private JMenu _help_jmenu;
98 private JMenuItem _website_item;
99 private JMenuItem _phyloxml_website_item;
100 private JMenuItem _phyloxml_ref_item;
101 private JMenuItem _aptx_ref_item;
102 private JMenuItem _remove_branch_color_item;
103 private JMenuItem _remove_visual_styles_item;
104 private JCheckBoxMenuItem _show_domain_labels;
105 private JCheckBoxMenuItem _show_annotation_ref_source;
106 private JCheckBoxMenuItem _color_labels_same_as_parent_branch;
107 private JCheckBoxMenuItem _abbreviate_scientific_names;
108 private JCheckBoxMenuItem _screen_antialias_cbmi;
109 private JCheckBoxMenuItem _background_gradient_cbmi;
110 private JCheckBoxMenuItem _color_by_taxonomic_group_cbmi;
111 private JRadioButtonMenuItem _non_lined_up_cladograms_rbmi;
112 private JRadioButtonMenuItem _uniform_cladograms_rbmi;
113 private JRadioButtonMenuItem _ext_node_dependent_cladogram_rbmi;
114 private Options _options;
115 private JMenuItem _choose_font_mi;
116 private JMenuItem _switch_colors_mi;
117 JCheckBoxMenuItem _label_direction_cbmi;
118 private JCheckBoxMenuItem _show_scale_cbmi;
119 private JCheckBoxMenuItem _search_case_senstive_cbmi;
120 private JCheckBoxMenuItem _search_whole_words_only_cbmi;
121 private JCheckBoxMenuItem _inverse_search_result_cbmi;
122 private JCheckBoxMenuItem _search_with_regex_cbmi;
123 private JCheckBoxMenuItem _show_overview_cbmi;
124 private JMenuItem _choose_minimal_confidence_mi;
125 private JMenuItem _collapse_species_specific_subtrees;
126 private JMenuItem _overview_placment_mi;
127 private ButtonGroup _radio_group_1;
128 private JCheckBoxMenuItem _show_default_node_shapes_internal_cbmi;
129 private JCheckBoxMenuItem _show_default_node_shapes_external_cbmi;
130 private JCheckBoxMenuItem _show_default_node_shapes_for_marked_cbmi;
131 private JMenuItem _cycle_node_shape_mi;
132 private JMenuItem _cycle_node_fill_mi;
133 private JMenuItem _choose_node_size_mi;
134 private JCheckBoxMenuItem _show_confidence_stddev_cbmi;
135 private final LinkedList<TextFrame> _textframes = new LinkedList<TextFrame>();
136 private JMenu _analysis_menu;
137 private JMenuItem _gsdi_item;
138 private JMenuItem _gsdir_item;
139 private Phylogeny _species_tree;
140 private JCheckBoxMenuItem _right_line_up_domains_cbmi;
141 private JCheckBoxMenuItem _line_up_renderable_data_cbmi;
143 JMenuItem _open_item;
144 JMenuItem _open_url_item;
145 JMenuItem _save_item;
146 JMenuItem _save_all_item;
147 JMenuItem _close_item;
148 JMenuItem _exit_item;
150 JMenuItem _print_item;
151 JMenuItem _write_to_pdf_item;
152 JMenuItem _write_to_jpg_item;
153 JMenuItem _write_to_gif_item;
154 JMenuItem _write_to_tif_item;
155 JMenuItem _write_to_png_item;
156 JMenuItem _write_to_bmp_item;
160 void writePhylogenyToGraphicsFile( final String file_name, final GraphicsExportType type ) {
161 _mainpanel.getCurrentTreePanel().calcParametersForPainting( _mainpanel.getCurrentTreePanel().getWidth(),
162 _mainpanel.getCurrentTreePanel().getHeight() );
163 String file_written_to = "";
164 boolean error = false;
166 file_written_to = AptxUtil.writePhylogenyToGraphicsFile( file_name,
167 _mainpanel.getCurrentTreePanel().getWidth(),
168 _mainpanel.getCurrentTreePanel().getHeight(),
169 _mainpanel.getCurrentTreePanel(),
170 _mainpanel.getControlPanel(),
174 catch ( final IOException e ) {
176 JOptionPane.showMessageDialog( this, e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE );
179 if ( ( file_written_to != null ) && ( file_written_to.length() > 0 ) ) {
180 JOptionPane.showMessageDialog( this,
181 "Wrote image to: " + file_written_to,
183 JOptionPane.INFORMATION_MESSAGE );
186 JOptionPane.showMessageDialog( this,
187 "There was an unknown problem when attempting to write to an image file: \""
190 JOptionPane.ERROR_MESSAGE );
193 _contentpane.repaint();
196 void writeToFile( final Phylogeny t ) {
200 String initial_filename = null;
201 if ( getMainPanel().getCurrentTreePanel().getTreeFile() != null ) {
203 initial_filename = getMainPanel().getCurrentTreePanel().getTreeFile().getCanonicalPath();
205 catch ( final IOException e ) {
206 initial_filename = null;
209 if ( !ForesterUtil.isEmpty( initial_filename ) ) {
210 _save_filechooser.setSelectedFile( new File( initial_filename ) );
213 _save_filechooser.setSelectedFile( new File( "" ) );
215 final File my_dir = getCurrentDir();
216 if ( my_dir != null ) {
217 _save_filechooser.setCurrentDirectory( my_dir );
219 final int result = _save_filechooser.showSaveDialog( _contentpane );
220 final File file = _save_filechooser.getSelectedFile();
221 setCurrentDir( _save_filechooser.getCurrentDirectory() );
222 boolean exception = false;
223 if ( ( file != null ) && ( result == JFileChooser.APPROVE_OPTION ) ) {
224 if ( file.exists() ) {
225 final int i = JOptionPane.showConfirmDialog( this,
226 file + " already exists.\nOverwrite?",
228 JOptionPane.OK_CANCEL_OPTION,
229 JOptionPane.QUESTION_MESSAGE );
230 if ( i != JOptionPane.OK_OPTION ) {
234 final File to = new File( file.getAbsoluteFile().toString() + Constants.BACKUP_FILE_SUFFIX );
236 ForesterUtil.copyFile( file, to );
238 catch ( final Exception e ) {
239 JOptionPane.showMessageDialog( this,
240 "Failed to create backup copy " + to,
241 "Failed to Create Backup Copy",
242 JOptionPane.WARNING_MESSAGE );
247 catch ( final Exception e ) {
248 JOptionPane.showMessageDialog( this,
249 "Failed to delete: " + file,
251 JOptionPane.WARNING_MESSAGE );
255 if ( _save_filechooser.getFileFilter() == MainFrame.nhfilter ) {
256 exception = writeAsNewHampshire( t, exception, file );
258 else if ( _save_filechooser.getFileFilter() == MainFrame.xmlfilter ) {
259 exception = writeAsPhyloXml( t, exception, file );
261 else if ( _save_filechooser.getFileFilter() == MainFrame.nexusfilter ) {
262 exception = writeAsNexus( t, exception, file );
266 final String file_name = file.getName().trim().toLowerCase();
267 if ( file_name.endsWith( ".nh" ) || file_name.endsWith( ".newick" ) || file_name.endsWith( ".phy" )
268 || file_name.endsWith( ".tree" ) ) {
269 exception = writeAsNewHampshire( t, exception, file );
271 else if ( file_name.endsWith( ".nex" ) || file_name.endsWith( ".nexus" ) ) {
272 exception = writeAsNexus( t, exception, file );
276 exception = writeAsPhyloXml( t, exception, file );
280 getMainPanel().setTitleOfSelectedTab( file.getName() );
281 getMainPanel().getCurrentTreePanel().setTreeFile( file );
282 getMainPanel().getCurrentTreePanel().setEdited( false );
287 void writeToGraphicsFile( final Phylogeny t, final GraphicsExportType type ) {
288 if ( ( t == null ) || t.isEmpty() ) {
291 String initial_filename = "";
292 if ( getMainPanel().getCurrentTreePanel().getTreeFile() != null ) {
293 initial_filename = getMainPanel().getCurrentTreePanel().getTreeFile().toString();
295 if ( initial_filename.indexOf( '.' ) > 0 ) {
296 initial_filename = initial_filename.substring( 0, initial_filename.lastIndexOf( '.' ) );
298 initial_filename = initial_filename + "." + type;
299 _writetographics_filechooser.setSelectedFile( new File( initial_filename ) );
300 final File my_dir = getCurrentDir();
301 if ( my_dir != null ) {
302 _writetographics_filechooser.setCurrentDirectory( my_dir );
304 final int result = _writetographics_filechooser.showSaveDialog( _contentpane );
305 File file = _writetographics_filechooser.getSelectedFile();
306 setCurrentDir( _writetographics_filechooser.getCurrentDirectory() );
307 if ( ( file != null ) && ( result == JFileChooser.APPROVE_OPTION ) ) {
308 if ( !file.toString().toLowerCase().endsWith( type.toString() ) ) {
309 file = new File( file.toString() + "." + type );
311 if ( file.exists() ) {
312 final int i = JOptionPane.showConfirmDialog( this,
313 file + " already exists. Overwrite?",
315 JOptionPane.OK_CANCEL_OPTION,
316 JOptionPane.WARNING_MESSAGE );
317 if ( i != JOptionPane.OK_OPTION ) {
324 catch ( final Exception e ) {
325 JOptionPane.showMessageDialog( this,
326 "Failed to delete: " + file,
328 JOptionPane.WARNING_MESSAGE );
332 writePhylogenyToGraphicsFile( file.toString(), type );
336 void writeToPdf( final Phylogeny t ) {
337 if ( ( t == null ) || t.isEmpty() ) {
340 String initial_filename = "";
341 if ( getMainPanel().getCurrentTreePanel().getTreeFile() != null ) {
342 initial_filename = getMainPanel().getCurrentTreePanel().getTreeFile().toString();
344 if ( initial_filename.indexOf( '.' ) > 0 ) {
345 initial_filename = initial_filename.substring( 0, initial_filename.lastIndexOf( '.' ) );
347 initial_filename = initial_filename + ".pdf";
348 _writetopdf_filechooser.setSelectedFile( new File( initial_filename ) );
349 final File my_dir = getCurrentDir();
350 if ( my_dir != null ) {
351 _writetopdf_filechooser.setCurrentDirectory( my_dir );
353 final int result = _writetopdf_filechooser.showSaveDialog( _contentpane );
354 File file = _writetopdf_filechooser.getSelectedFile();
355 setCurrentDir( _writetopdf_filechooser.getCurrentDirectory() );
356 if ( ( file != null ) && ( result == JFileChooser.APPROVE_OPTION ) ) {
357 if ( !file.toString().toLowerCase().endsWith( ".pdf" ) ) {
358 file = new File( file.toString() + ".pdf" );
360 if ( file.exists() ) {
361 final int i = JOptionPane.showConfirmDialog( this,
362 file + " already exists. Overwrite?",
364 JOptionPane.OK_CANCEL_OPTION,
365 JOptionPane.WARNING_MESSAGE );
366 if ( i != JOptionPane.OK_OPTION ) {
370 printPhylogenyToPdf( file.toString() );
374 void buildFileMenu() {
375 _file_jmenu = MainFrame.createMenu( "File", getConfiguration() );
376 _file_jmenu.add( _save_item = new JMenuItem( "Save Tree As..." ) );
377 _file_jmenu.addSeparator();
378 _file_jmenu.add( _write_to_pdf_item = new JMenuItem( "Export to PDF file ..." ) );
379 if ( AptxUtil.canWriteFormat( "tif" ) || AptxUtil.canWriteFormat( "tiff" ) || AptxUtil.canWriteFormat( "TIF" ) ) {
380 _file_jmenu.add( _write_to_tif_item = new JMenuItem( "Export to TIFF file..." ) );
382 _file_jmenu.add( _write_to_png_item = new JMenuItem( "Export to PNG file..." ) );
383 _file_jmenu.add( _write_to_jpg_item = new JMenuItem( "Export to JPG file..." ) );
384 if ( AptxUtil.canWriteFormat( "gif" ) ) {
385 _file_jmenu.add( _write_to_gif_item = new JMenuItem( "Export to GIF file..." ) );
387 if ( AptxUtil.canWriteFormat( "bmp" ) ) {
388 _file_jmenu.add( _write_to_bmp_item = new JMenuItem( "Export to BMP file..." ) );
390 _file_jmenu.addSeparator();
391 _file_jmenu.add( _print_item = new JMenuItem( "Print..." ) );
392 _file_jmenu.addSeparator();
393 _file_jmenu.add( _exit_item = new JMenuItem( "Exit" ) );
394 customizeJMenuItem( _save_item );
395 customizeJMenuItem( _write_to_pdf_item );
396 customizeJMenuItem( _write_to_png_item );
397 customizeJMenuItem( _write_to_jpg_item );
398 customizeJMenuItem( _write_to_gif_item );
399 customizeJMenuItem( _write_to_tif_item );
400 customizeJMenuItem( _write_to_bmp_item );
401 customizeJMenuItem( _print_item );
402 customizeJMenuItem( _exit_item );
403 _jmenubar.add( _file_jmenu );
407 public void actionPerformed( final ActionEvent e ) {
408 final Object o = e.getSource();
409 if ( o == _midpoint_root_item ) {
410 getMainPanel().getCurrentTreePanel().midpointRoot();
412 else if ( o == _gsdi_item ) {
413 if ( isSubtreeDisplayed() ) {
418 else if ( o == _gsdir_item ) {
419 if ( isSubtreeDisplayed() ) {
424 else if ( o == _taxcolor_item ) {
425 getMainPanel().getCurrentTreePanel().taxColor();
427 else if ( o == _confcolor_item ) {
428 getMainPanel().getCurrentTreePanel().confColor();
430 else if ( o == _collapse_species_specific_subtrees ) {
431 if ( getCurrentTreePanel() != null ) {
432 getCurrentTreePanel().collapseSpeciesSpecificSubtrees();
435 else if ( o == _remove_branch_color_item ) {
436 removeBranchColors();
438 else if ( o == _remove_visual_styles_item ) {
439 removeVisualStyles();
441 else if ( o == _switch_colors_mi ) {
444 else if ( o == _display_basic_information_item ) {
445 displayBasicInformation();
447 else if ( o == _view_as_NH_item ) {
450 else if ( o == _view_as_XML_item ) {
453 else if ( o == _view_as_nexus_item ) {
456 else if ( o == _super_tiny_fonts_mi ) {
457 if ( getCurrentTreePanel() != null ) {
458 getCurrentTreePanel().setSuperTinyFonts();
459 getCurrentTreePanel().repaint();
462 else if ( o == _tiny_fonts_mi ) {
463 if ( getCurrentTreePanel() != null ) {
464 getCurrentTreePanel().setTinyFonts();
465 getCurrentTreePanel().repaint();
468 else if ( o == _small_fonts_mi ) {
469 if ( getCurrentTreePanel() != null ) {
470 getCurrentTreePanel().setSmallFonts();
471 getCurrentTreePanel().repaint();
474 else if ( o == _medium_fonts_mi ) {
475 if ( getCurrentTreePanel() != null ) {
476 getCurrentTreePanel().setMediumFonts();
477 getCurrentTreePanel().repaint();
480 else if ( o == _large_fonts_mi ) {
481 if ( getCurrentTreePanel() != null ) {
482 getCurrentTreePanel().setLargeFonts();
483 getCurrentTreePanel().repaint();
486 else if ( o == _choose_font_mi ) {
489 else if ( o == _choose_minimal_confidence_mi ) {
490 chooseMinimalConfidence();
492 else if ( o == _choose_node_size_mi ) {
493 MainFrame.chooseNodeSize( getOptions(), this );
495 else if ( o == _overview_placment_mi ) {
496 MainFrame.cycleOverview( getOptions(), getCurrentTreePanel() );
498 else if ( o == _cycle_node_fill_mi ) {
499 MainFrame.cycleNodeFill( getOptions() );
501 else if ( o == _cycle_node_shape_mi ) {
502 MainFrame.cycleNodeShape( getOptions() );
504 else if ( o == _non_lined_up_cladograms_rbmi ) {
505 updateOptions( getOptions() );
506 _mainpanel.getControlPanel().showWhole();
508 else if ( o == _uniform_cladograms_rbmi ) {
509 updateOptions( getOptions() );
510 _mainpanel.getControlPanel().showWhole();
512 else if ( o == _ext_node_dependent_cladogram_rbmi ) {
513 updateOptions( getOptions() );
514 _mainpanel.getControlPanel().showWhole();
516 else if ( o == _search_case_senstive_cbmi ) {
517 updateOptions( getOptions() );
518 getMainPanel().getControlPanel().search0();
519 getMainPanel().getControlPanel().search1();
521 else if ( o == _search_whole_words_only_cbmi ) {
522 if ( ( _search_with_regex_cbmi != null ) && _search_whole_words_only_cbmi.isSelected() ) {
523 _search_with_regex_cbmi.setSelected( false );
525 updateOptions( getOptions() );
526 getMainPanel().getControlPanel().search0();
527 getMainPanel().getControlPanel().search1();
529 else if ( o == _inverse_search_result_cbmi ) {
530 updateOptions( getOptions() );
531 getMainPanel().getControlPanel().search0();
532 getMainPanel().getControlPanel().search1();
534 else if ( o == _search_with_regex_cbmi ) {
535 if ( ( _search_whole_words_only_cbmi != null ) && _search_with_regex_cbmi.isSelected() ) {
536 _search_whole_words_only_cbmi.setSelected( false );
538 if ( ( _search_case_senstive_cbmi != null ) && _search_with_regex_cbmi.isSelected() ) {
539 _search_case_senstive_cbmi.setSelected( true );
541 updateOptions( getOptions() );
542 getMainPanel().getControlPanel().search0();
543 getMainPanel().getControlPanel().search1();
545 else if ( o == _show_scale_cbmi ) {
546 updateOptions( getOptions() );
548 else if ( o == _show_confidence_stddev_cbmi ) {
549 updateOptions( getOptions() );
551 else if ( o == _label_direction_cbmi ) {
552 updateOptions( getOptions() );
554 else if ( o == _abbreviate_scientific_names ) {
555 updateOptions( getOptions() );
557 else if ( o == _show_overview_cbmi ) {
558 updateOptions( getOptions() );
559 if ( getCurrentTreePanel() != null ) {
560 getCurrentTreePanel().updateOvSizes();
563 else if ( ( o == _rectangular_type_cbmi ) || ( o == _triangular_type_cbmi ) || ( o == _curved_type_cbmi )
564 || ( o == _convex_type_cbmi ) || ( o == _rounded_type_cbmi ) || ( o == _euro_type_cbmi )
565 || ( o == _unrooted_type_cbmi ) || ( o == _circular_type_cbmi ) ) {
568 else if ( o == _screen_antialias_cbmi ) {
569 updateOptions( getOptions() );
570 setupScreenTextAntialias( getMainPanel().getTreePanels(), isScreenAntialias() );
572 else if ( o == _background_gradient_cbmi ) {
573 updateOptions( getOptions() );
575 else if ( o == _show_domain_labels ) {
576 updateOptions( getOptions() );
578 else if ( o == _color_labels_same_as_parent_branch ) {
579 updateOptions( getOptions() );
581 else if ( o == _show_default_node_shapes_internal_cbmi ) {
582 updateOptions( getOptions() );
584 else if ( o == _show_default_node_shapes_external_cbmi ) {
585 updateOptions( getOptions() );
587 else if ( o == _about_item ) {
590 else if ( o == _help_item ) {
592 AptxUtil.openWebsite( Constants.APTX_DOC_SITE, true, this );
594 catch ( final IOException e1 ) {
595 ForesterUtil.printErrorMessage( Constants.PRG_NAME, e1.toString() );
598 else if ( o == _website_item ) {
600 AptxUtil.openWebsite( Constants.APTX_WEB_SITE, true, this );
602 catch ( final IOException e1 ) {
603 ForesterUtil.printErrorMessage( Constants.PRG_NAME, e1.toString() );
606 else if ( o == _phyloxml_website_item ) {
608 AptxUtil.openWebsite( Constants.PHYLOXML_WEB_SITE, true, this );
610 catch ( final IOException e1 ) {
611 ForesterUtil.printErrorMessage( Constants.PRG_NAME, e1.toString() );
614 else if ( o == _aptx_ref_item ) {
616 AptxUtil.openWebsite( Constants.APTX_REFERENCE_URL, true, this );
618 catch ( final IOException e1 ) {
619 ForesterUtil.printErrorMessage( Constants.PRG_NAME, e1.toString() );
622 else if ( o == _phyloxml_ref_item ) {
624 AptxUtil.openWebsite( Constants.PHYLOXML_REFERENCE_URL, true, this );
626 catch ( final IOException e1 ) {
627 ForesterUtil.printErrorMessage( Constants.PRG_NAME, e1.toString() );
630 else if ( o == _color_by_taxonomic_group_cbmi ) {
631 updateOptions( getOptions() );
633 else if ( o == _line_up_renderable_data_cbmi ) {
634 if ( !_line_up_renderable_data_cbmi.isSelected() ) {
635 _right_line_up_domains_cbmi.setSelected( false );
637 updateOptions( getOptions() );
639 else if ( o == _right_line_up_domains_cbmi ) {
640 if ( _right_line_up_domains_cbmi.isSelected() ) {
641 _line_up_renderable_data_cbmi.setSelected( true );
643 updateOptions( getOptions() );
646 else if ( o == _write_to_pdf_item ) {
647 writeToPdf( _mainpanel.getCurrentPhylogeny() );
650 else if ( o == _write_to_jpg_item ) {
651 writeToGraphicsFile( _mainpanel.getCurrentPhylogeny(), GraphicsExportType.JPG );
653 else if ( o == _write_to_gif_item ) {
654 writeToGraphicsFile( _mainpanel.getCurrentPhylogeny(), GraphicsExportType.GIF );
656 else if ( o == _write_to_tif_item ) {
657 writeToGraphicsFile( _mainpanel.getCurrentPhylogeny(), GraphicsExportType.TIFF );
659 else if ( o == _write_to_bmp_item ) {
660 writeToGraphicsFile( _mainpanel.getCurrentPhylogeny(), GraphicsExportType.BMP );
662 else if ( o == _write_to_png_item ) {
663 writeToGraphicsFile( _mainpanel.getCurrentPhylogeny(), GraphicsExportType.PNG );
665 else if ( o == _print_item ) {
666 MainFrame.print( getCurrentTreePanel(),
672 else if ( o == _save_item ) {
673 writeToFile( _mainpanel.getCurrentPhylogeny() );
676 // else if ( o == _graphics_export_visible_only_cbmi ) {
677 // updateOptions( getOptions() );
679 // else if ( o == _antialias_print_cbmi ) {
680 // updateOptions( getOptions() );
682 // else if ( o == _print_black_and_white_cbmi ) {
683 // updateOptions( getOptions() );
685 // else if ( o == _print_using_actual_size_cbmi ) {
686 // updateOptions( getOptions() );
688 // else if ( o == _graphics_export_using_actual_size_cbmi ) {
689 // updateOptions( getOptions() );
691 // else if ( o == _print_size_mi ) {
692 // choosePrintSize();
694 // else if ( o == _choose_pdf_width_mi ) {
702 public void destroy() {
703 AptxUtil.printAppletMessage( NAME, "going to be destroyed " );
704 removeAllTextFrames();
705 if ( getMainPanel() != null ) {
706 getMainPanel().terminate();
711 * This method returns the current external node data which
712 * has been selected by the user by clicking the "Return ..."
713 * menu item. This method is expected to be called from Javascript or
716 * @return current external node data as String
718 public String getCurrentExternalNodesDataBuffer() {
719 return getCurrentTreePanel().getCurrentExternalNodesDataBufferAsString();
722 public int getCurrentExternalNodesDataBufferChangeCounter() {
723 return getCurrentTreePanel().getCurrentExternalNodesDataBufferChangeCounter();
726 public int getCurrentExternalNodesDataBufferLength() {
727 return getCurrentTreePanel().getCurrentExternalNodesDataBufferAsString().length();
731 * This method returns the current phylogeny as a string in the chosen format
733 * @param format must be NH, NHX, NEXUS or PHYLOXML
734 * @return the phylogeny string
735 * @author Herve Menager
737 public String getCurrentPhylogeny( final String format ) {
738 removeAllTextFrames();
739 if ( ( getMainPanel().getCurrentPhylogeny() == null ) || getMainPanel().getCurrentPhylogeny().isEmpty()
740 || ( getMainPanel().getCurrentPhylogeny().getNumberOfExternalNodes() > 10000 ) ) {
743 switch ( ForesterConstants.PhylogeneticTreeFormats.valueOf( format ) ) {
745 return getMainPanel().getCurrentPhylogeny().toNewHampshire();
747 return getMainPanel().getCurrentPhylogeny().toNewHampshireX();
749 return getMainPanel().getCurrentPhylogeny().toNexus();
751 return getMainPanel().getCurrentPhylogeny().toPhyloXML( -1 );
759 * This method returns a view of the current phylogeny in a chosen
760 * graphics format, base64-encoded in a string so that in can be used
763 * @param format must be GraphicsExportType (gif, jpg, pdf, png, tif, bmp)
764 * @return the phylogeny string
765 * @author Herve Menager
767 public String getCurrentPhylogenyGraphicsAsBase64EncodedString( final String format ) {
768 final ByteArrayOutputStream baos = new ByteArrayOutputStream();
770 AptxUtil.writePhylogenyToGraphicsByteArrayOutputStream( baos,
771 _mainpanel.getWidth(),
772 _mainpanel.getHeight(),
773 getCurrentTreePanel(),
774 getCurrentTreePanel().getControlPanel(),
775 GraphicsExportType.valueOf( format ),
778 catch ( final IOException ioe ) {
779 ForesterUtil.printErrorMessage( NAME, ioe.toString() );
780 ioe.printStackTrace();
781 JOptionPane.showMessageDialog( this,
782 NAME + ": Failed to generate graphics: " + "\nException: " + ioe,
783 "Failed to generate graphics",
784 JOptionPane.ERROR_MESSAGE );
787 final byte[] bytes = baos.toByteArray();
788 final String dataImg = Base64.encodeBase64String( bytes );
792 public Options getOptions() {
798 final String config_filename = getParameter( Constants.APPLET_PARAM_NAME_FOR_CONFIG_FILE_URL );
799 AptxUtil.printAppletMessage( NAME, "URL for configuration file is: " + config_filename );
800 final Configuration configuration = new Configuration( config_filename, true, true, true );
801 setConfiguration( configuration );
802 setOptions( Options.createInstance( configuration ) );
804 final String tree_url_str = getParameter( Constants.APPLET_PARAM_NAME_FOR_URL_OF_TREE_TO_LOAD );
805 if ( ForesterUtil.isEmpty( tree_url_str ) ) {
806 ForesterUtil.printErrorMessage( NAME, "could not get tree URL from "
807 + Constants.APPLET_PARAM_NAME_FOR_URL_OF_TREE_TO_LOAD );
808 JOptionPane.showMessageDialog( this, NAME + ": could not get tree URL from "
809 + Constants.APPLET_PARAM_NAME_FOR_URL_OF_TREE_TO_LOAD, "Failed get URL", JOptionPane.ERROR_MESSAGE );
812 AptxUtil.printAppletMessage( NAME, "URL for phylogenies is " + tree_url_str );
813 // Get URL to tree file
816 phys_url = new URL( tree_url_str );
818 catch ( final Exception e ) {
819 ForesterUtil.printErrorMessage( NAME, "error: " + e );
821 JOptionPane.showMessageDialog( this, NAME + ": Could not create URL from: \"" + tree_url_str
822 + "\"\nException: " + e, "Failed to create URL", JOptionPane.ERROR_MESSAGE );
824 if ( phys_url == null ) {
825 ForesterUtil.printErrorMessage( NAME, "failed to get tree URL from "
826 + Constants.APPLET_PARAM_NAME_FOR_URL_OF_TREE_TO_LOAD );
827 JOptionPane.showMessageDialog( this,
828 NAME + ": Could not create URL from: \"" + tree_url_str,
829 "Failed to create URL",
830 JOptionPane.ERROR_MESSAGE );
833 // Load the tree from URL
834 Phylogeny[] phys = null;
836 phys = AptxUtil.readPhylogeniesFromUrl( phys_url,
837 getConfiguration().isValidatePhyloXmlAgainstSchema(),
838 getConfiguration().isReplaceUnderscoresInNhParsing(),
839 getConfiguration().isInternalNumberAreConfidenceForNhParsing(),
840 getConfiguration().getTaxonomyExtraction(),
841 getConfiguration().isMidpointReroot() );
843 catch ( final Exception e ) {
844 ForesterUtil.printErrorMessage( NAME, e.toString() );
846 JOptionPane.showMessageDialog( this,
847 NAME + ": Failed to read phylogenies: " + "\nException: " + e,
848 "Failed to read phylogenies",
849 JOptionPane.ERROR_MESSAGE );
851 if ( phys == null ) {
852 ForesterUtil.printErrorMessage( NAME, "phylogenies from [" + phys_url + "] are null" );
853 JOptionPane.showMessageDialog( this,
854 NAME + ": phylogenies from [" + phys_url + "] are null",
855 "Failed to read phylogenies",
856 JOptionPane.ERROR_MESSAGE );
859 else if ( phys.length < 1 ) {
860 ForesterUtil.printErrorMessage( NAME, "phylogenies from [" + phys_url + "] are empty" );
861 JOptionPane.showMessageDialog( this,
862 NAME + ": phylogenies from [" + phys_url + "] are empty",
863 "Failed to read phylogenies",
864 JOptionPane.ERROR_MESSAGE );
868 AptxUtil.printAppletMessage( NAME, "loaded " + phys.length + " phylogenies from: " + phys_url );
871 final String species_tree_url_str = getParameter( Constants.APPLET_PARAM_NAME_FOR_URL_OF_SPECIES_TREE_TO_LOAD );
872 if ( !ForesterUtil.isEmpty( species_tree_url_str ) ) {
873 AptxUtil.printAppletMessage( NAME, "URL of species tree to load: \"" + species_tree_url_str + "\"" );
874 Phylogeny[] species_trees = null;
876 final URL species_tree_url = new URL( species_tree_url_str );
877 species_trees = AptxUtil.readPhylogeniesFromUrl( species_tree_url,
878 configuration.isValidatePhyloXmlAgainstSchema(),
879 configuration.isReplaceUnderscoresInNhParsing(),
881 TAXONOMY_EXTRACTION.NO,
884 catch ( final IOException e ) {
885 ForesterUtil.printErrorMessage( NAME, "could not read species tree from [" + species_tree_url_str
887 JOptionPane.showMessageDialog( this, NAME + ": could not read species tree from ["
888 + species_tree_url_str + "]", "Failed to read species tree", JOptionPane.ERROR_MESSAGE );
890 if ( ( species_trees != null ) && ( species_trees.length > 0 ) ) {
891 AptxUtil.printAppletMessage( NAME, "successfully read species tree" );
892 if ( species_trees[ 0 ].isEmpty() ) {
893 ForesterUtil.printErrorMessage( NAME, "species tree is empty" );
895 else if ( !species_trees[ 0 ].isRooted() ) {
896 ForesterUtil.printErrorMessage( NAME, "species tree is not rooted" );
899 setSpeciesTree( species_trees[ 0 ] );
900 AptxUtil.printAppletMessage( NAME, "species tree OK" );
907 setMainPanel( new MainPanelApplets( getConfiguration(), this ) );
908 _jmenubar = new JMenuBar();
909 if ( !getConfiguration().isHideControlPanelAndMenubar() ) {
911 if ( !getConfiguration().isUseNativeUI() ) {
912 _jmenubar.setBackground( getConfiguration().getGuiMenuBackgroundColor() );
914 if ( getSpeciesTree() != null ) {
923 setJMenuBar( _jmenubar );
925 final Container contentpane = getContentPane();
926 contentpane.setLayout( new BorderLayout() );
927 contentpane.add( getMainPanel(), BorderLayout.CENTER );
928 addComponentListener( new ComponentAdapter() {
931 public void componentResized( final ComponentEvent e ) {
932 if ( getMainPanel().getCurrentTreePanel() != null ) {
933 getMainPanel().getCurrentTreePanel().calcParametersForPainting( getMainPanel()
934 .getCurrentTreePanel()
937 .getCurrentTreePanel()
942 if ( getConfiguration().isUseTabbedDisplay() ) {
944 AptxUtil.printAppletMessage( NAME, "using tabbed display" );
945 AptxUtil.addPhylogeniesToTabs( phys,
946 new File( phys_url.getFile() ).getName(),
951 catch ( final Exception e ) {
952 ForesterUtil.printErrorMessage( NAME, e.toString() );
957 AptxUtil.printAppletMessage( NAME, "not using tabbed display" );
958 if ( getSpeciesTree() != null ) {
959 AptxUtil.printAppletMessage( NAME,
960 "Warning: gsdi (gene duplication inference) only available tabbed display" );
962 AptxUtil.addPhylogenyToPanel( phys, getConfiguration(), getMainPanel() );
966 getMainPanel().getControlPanel().showWholeAll();
967 getMainPanel().getControlPanel().showWhole();
969 getCurrentTreePanel().getControlPanel().getSequenceRelationTypeBox().removeAllItems();
970 for( final SequenceRelation.SEQUENCE_RELATION_TYPE type : getMainPanel().getCurrentPhylogeny()
971 .getRelevantSequenceRelationTypes() ) {
972 getCurrentTreePanel().getControlPanel().getSequenceRelationTypeBox().addItem( type );
974 final String default_relation = getParameter( Constants.APPLET_PARAM_NAME_FOR_DEFAULT_SEQUENCE_RELATION_TYPE );
975 if ( default_relation != null ) {
976 getCurrentTreePanel().getControlPanel().getSequenceRelationTypeBox().setSelectedItem( default_relation );
978 final String default_sequence = getParameter( Constants.APPLET_PARAM_NAME_FOR_DEFAULT_QUERY_SEQUENCE );
979 if ( default_sequence != null ) {
980 getCurrentTreePanel().getControlPanel().getSequenceRelationBox().setSelectedItem( default_sequence );
984 AptxUtil.printAppletMessage( NAME, "successfully initialized" );
987 catch ( final Exception e ) {
988 ForesterUtil.printErrorMessage( NAME, e.toString() );
993 public void showTextFrame( final String s, final String title ) {
995 _textframes.addLast( TextFrame.instantiate( s, title, _textframes ) );
999 public void start() {
1000 if ( getMainPanel() != null ) {
1001 getMainPanel().validate();
1004 requestFocusInWindow();
1006 AptxUtil.printAppletMessage( NAME, "started" );
1009 void buildAnalysisMenu() {
1010 _analysis_menu = MainFrame.createMenu( "Analysis", getConfiguration() );
1011 _analysis_menu.add( _gsdi_item = new JMenuItem( "GSDI (Generalized Speciation Duplication Inference)" ) );
1012 _analysis_menu.add( _gsdir_item = new JMenuItem( "GSDIR (GSDI with re-rooting)" ) );
1013 customizeJMenuItem( _gsdi_item );
1014 customizeJMenuItem( _gsdir_item );
1015 // _analysis_menu.addSeparator();
1016 // _analysis_menu.add( _lineage_inference = new JMenuItem( INFER_ANCESTOR_TAXONOMIES ) );
1017 // customizeJMenuItem( _lineage_inference );
1018 // _lineage_inference.setToolTipText( "Inference of ancestor taxonomies/lineages" );
1019 _jmenubar.add( _analysis_menu );
1022 void buildFontSizeMenu() {
1023 _font_size_menu = MainFrame.createMenu( MainFrame.FONT_SIZE_MENU_LABEL, getConfiguration() );
1024 _font_size_menu.add( _super_tiny_fonts_mi = new JMenuItem( "Super tiny fonts" ) );
1025 _font_size_menu.add( _tiny_fonts_mi = new JMenuItem( "Tiny fonts" ) );
1026 _font_size_menu.add( _small_fonts_mi = new JMenuItem( "Small fonts" ) );
1027 _font_size_menu.add( _medium_fonts_mi = new JMenuItem( "Medium fonts" ) );
1028 _font_size_menu.add( _large_fonts_mi = new JMenuItem( "Large fonts" ) );
1029 customizeJMenuItem( _super_tiny_fonts_mi );
1030 customizeJMenuItem( _tiny_fonts_mi );
1031 customizeJMenuItem( _small_fonts_mi );
1032 customizeJMenuItem( _medium_fonts_mi );
1033 customizeJMenuItem( _large_fonts_mi );
1034 _jmenubar.add( _font_size_menu );
1037 void buildHelpMenu() {
1038 _help_jmenu = MainFrame.createMenu( "Help", getConfiguration() );
1039 _help_jmenu.add( _help_item = new JMenuItem( "Documentation" ) );
1040 _help_jmenu.addSeparator();
1041 _help_jmenu.add( _website_item = new JMenuItem( "Archaeopteryx Home" ) );
1042 _aptx_ref_item = new JMenuItem( "Archaeopteryx Reference" );
1043 _help_jmenu.add( _phyloxml_website_item = new JMenuItem( "phyloXML Home" ) );
1044 _help_jmenu.add( _phyloxml_ref_item = new JMenuItem( "phyloXML Reference" ) );
1045 _help_jmenu.addSeparator();
1046 _help_jmenu.add( _about_item = new JMenuItem( "About" ) );
1047 customizeJMenuItem( _help_item );
1048 customizeJMenuItem( _website_item );
1049 customizeJMenuItem( _phyloxml_website_item );
1050 customizeJMenuItem( _aptx_ref_item );
1051 customizeJMenuItem( _phyloxml_ref_item );
1052 customizeJMenuItem( _about_item );
1053 _phyloxml_ref_item.setToolTipText( MainFrame.PHYLOXML_REF_TOOL_TIP );
1054 _aptx_ref_item.setToolTipText( MainFrame.APTX_REF_TOOL_TIP );
1055 _jmenubar.add( _help_jmenu );
1058 void buildOptionsMenu() {
1059 _options_jmenu = MainFrame.createMenu( MainFrame.OPTIONS_HEADER, getConfiguration() );
1060 _options_jmenu.addChangeListener( new ChangeListener() {
1063 public void stateChanged( final ChangeEvent e ) {
1064 MainFrame.setOvPlacementColorChooseMenuItem( _overview_placment_mi, getOptions() );
1065 MainFrame.setTextColorChooseMenuItem( _switch_colors_mi, getCurrentTreePanel() );
1067 .setTextMinSupportMenuItem( _choose_minimal_confidence_mi, getOptions(), getCurrentTreePanel() );
1068 MainFrame.setTextForFontChooserMenuItem( _choose_font_mi, MainFrame
1069 .createCurrentFontDesc( getMainPanel().getTreeFontSet() ) );
1070 MainFrame.setCycleNodeFillMenuItem( _cycle_node_fill_mi, getOptions() );
1071 MainFrame.setCycleNodeShapeMenuItem( _cycle_node_shape_mi, getOptions() );
1072 MainFrame.setTextNodeSizeMenuItem( _choose_node_size_mi, getOptions() );
1074 getMainPanel().getControlPanel().setVisibilityOfDomainStrucureCB();
1075 getMainPanel().getControlPanel().setVisibilityOfX();
1077 catch ( final Exception ignore ) {
1078 // do nothing, not important.
1082 _options_jmenu.add( MainFrame.customizeMenuItemAsLabel( new JMenuItem( MainFrame.DISPLAY_SUBHEADER ),
1083 getConfiguration() ) );
1085 .add( _ext_node_dependent_cladogram_rbmi = new JRadioButtonMenuItem( MainFrame.NONUNIFORM_CLADOGRAMS_LABEL ) );
1086 _options_jmenu.add( _uniform_cladograms_rbmi = new JRadioButtonMenuItem( MainFrame.UNIFORM_CLADOGRAMS_LABEL ) );
1088 .add( _non_lined_up_cladograms_rbmi = new JRadioButtonMenuItem( MainFrame.NON_LINED_UP_CLADOGRAMS_LABEL ) );
1089 _radio_group_1 = new ButtonGroup();
1090 _radio_group_1.add( _ext_node_dependent_cladogram_rbmi );
1091 _radio_group_1.add( _uniform_cladograms_rbmi );
1092 _radio_group_1.add( _non_lined_up_cladograms_rbmi );
1093 _options_jmenu.add( _show_overview_cbmi = new JCheckBoxMenuItem( MainFrame.SHOW_OVERVIEW_LABEL ) );
1094 _options_jmenu.add( _show_scale_cbmi = new JCheckBoxMenuItem( MainFrame.DISPLAY_SCALE_LABEL ) );
1096 .add( _show_default_node_shapes_internal_cbmi = new JCheckBoxMenuItem( MainFrame.DISPLAY_NODE_BOXES_LABEL_INT ) );
1098 .add( _show_default_node_shapes_external_cbmi = new JCheckBoxMenuItem( MainFrame.DISPLAY_NODE_BOXES_LABEL_EXT ) );
1100 .add( _show_default_node_shapes_for_marked_cbmi = new JCheckBoxMenuItem( MainFrame.DISPLAY_NODE_BOXES_LABEL_MARKED ) );
1101 _options_jmenu.add( _line_up_renderable_data_cbmi = new JCheckBoxMenuItem( MainFrame.LINE_UP_RENDERABLE_DATA ) );
1102 if ( getConfiguration().doDisplayOption( Configuration.show_domain_architectures ) ) {
1103 _options_jmenu.add( _right_line_up_domains_cbmi = new JCheckBoxMenuItem( MainFrame.RIGHT_LINE_UP_DOMAINS ) );
1104 _options_jmenu.add( _show_domain_labels = new JCheckBoxMenuItem( MainFrame.SHOW_DOMAIN_LABELS_LABEL ) );
1106 _options_jmenu.add( _show_annotation_ref_source = new JCheckBoxMenuItem( MainFrame.SHOW_ANN_REF_SOURCE_LABEL ) );
1107 _options_jmenu.add( _show_confidence_stddev_cbmi = new JCheckBoxMenuItem( MainFrame.SHOW_CONF_STDDEV_LABEL ) );
1109 .add( _color_by_taxonomic_group_cbmi = new JCheckBoxMenuItem( MainFrame.COLOR_BY_TAXONOMIC_GROUP ) );
1111 .add( _color_labels_same_as_parent_branch = new JCheckBoxMenuItem( MainFrame.COLOR_LABELS_LABEL ) );
1112 _color_labels_same_as_parent_branch.setToolTipText( MainFrame.COLOR_LABELS_TIP );
1113 _options_jmenu.add( _abbreviate_scientific_names = new JCheckBoxMenuItem( MainFrame.ABBREV_SN_LABEL ) );
1114 _options_jmenu.add( _label_direction_cbmi = new JCheckBoxMenuItem( MainFrame.LABEL_DIRECTION_LABEL ) );
1115 _label_direction_cbmi.setToolTipText( MainFrame.LABEL_DIRECTION_TIP );
1116 _options_jmenu.add( _screen_antialias_cbmi = new JCheckBoxMenuItem( MainFrame.SCREEN_ANTIALIAS_LABEL ) );
1117 _options_jmenu.add( _background_gradient_cbmi = new JCheckBoxMenuItem( MainFrame.BG_GRAD_LABEL ) );
1118 _options_jmenu.add( _cycle_node_shape_mi = new JMenuItem( MainFrame.CYCLE_NODE_SHAPE_LABEL ) );
1119 _options_jmenu.add( _cycle_node_fill_mi = new JMenuItem( MainFrame.CYCLE_NODE_FILL_LABEL ) );
1120 _options_jmenu.add( _choose_node_size_mi = new JMenuItem( MainFrame.CHOOSE_NODE_SIZE_LABEL ) );
1121 _options_jmenu.add( _choose_minimal_confidence_mi = new JMenuItem( "" ) );
1122 _options_jmenu.add( _overview_placment_mi = new JMenuItem( "" ) );
1123 _options_jmenu.add( _switch_colors_mi = new JMenuItem( "" ) );
1124 _options_jmenu.add( _choose_font_mi = new JMenuItem( "" ) );
1125 _options_jmenu.addSeparator();
1126 _options_jmenu.add( MainFrame.customizeMenuItemAsLabel( new JMenuItem( MainFrame.SEARCH_SUBHEADER ),
1127 getConfiguration() ) );
1129 .add( _search_case_senstive_cbmi = new JCheckBoxMenuItem( MainFrame.SEARCH_CASE_SENSITIVE_LABEL ) );
1130 _options_jmenu.add( _search_whole_words_only_cbmi = new JCheckBoxMenuItem( MainFrame.SEARCH_TERMS_ONLY_LABEL ) );
1131 _options_jmenu.add( _search_with_regex_cbmi = new JCheckBoxMenuItem( MainFrame.SEARCH_REGEX_LABEL ) );
1132 _search_with_regex_cbmi.setToolTipText( MainFrame.SEARCH_WITH_REGEX_TIP );
1134 .add( _inverse_search_result_cbmi = new JCheckBoxMenuItem( MainFrame.INVERSE_SEARCH_RESULT_LABEL ) );
1135 customizeJMenuItem( _choose_font_mi );
1136 customizeJMenuItem( _choose_minimal_confidence_mi );
1137 customizeJMenuItem( _switch_colors_mi );
1138 customizeJMenuItem( _overview_placment_mi );
1139 customizeCheckBoxMenuItem( _color_by_taxonomic_group_cbmi, getOptions().isColorByTaxonomicGroup() );
1140 customizeCheckBoxMenuItem( _label_direction_cbmi,
1141 getOptions().getNodeLabelDirection() == NODE_LABEL_DIRECTION.RADIAL );
1142 customizeCheckBoxMenuItem( _screen_antialias_cbmi, getOptions().isAntialiasScreen() );
1143 customizeCheckBoxMenuItem( _background_gradient_cbmi, getOptions().isBackgroundColorGradient() );
1144 customizeCheckBoxMenuItem( _show_domain_labels, getOptions().isShowDomainLabels() );
1145 customizeCheckBoxMenuItem( _show_annotation_ref_source, getOptions().isShowAnnotationRefSource() );
1146 customizeCheckBoxMenuItem( _abbreviate_scientific_names, getOptions().isAbbreviateScientificTaxonNames() );
1147 customizeCheckBoxMenuItem( _show_default_node_shapes_external_cbmi, getOptions()
1148 .isShowDefaultNodeShapesExternal() );
1149 customizeCheckBoxMenuItem( _show_default_node_shapes_internal_cbmi, getOptions()
1150 .isShowDefaultNodeShapesInternal() );
1151 customizeCheckBoxMenuItem( _show_default_node_shapes_for_marked_cbmi, getOptions()
1152 .isShowDefaultNodeShapesForMarkedNodes() );
1153 customizeJMenuItem( _cycle_node_shape_mi );
1154 customizeJMenuItem( _cycle_node_fill_mi );
1155 customizeJMenuItem( _choose_node_size_mi );
1156 customizeCheckBoxMenuItem( _color_labels_same_as_parent_branch, getOptions().isColorLabelsSameAsParentBranch() );
1157 customizeCheckBoxMenuItem( _search_case_senstive_cbmi, getOptions().isSearchCaseSensitive() );
1158 customizeCheckBoxMenuItem( _show_scale_cbmi, getOptions().isShowScale() );
1159 customizeRadioButtonMenuItem( _non_lined_up_cladograms_rbmi,
1160 getOptions().getCladogramType() == CLADOGRAM_TYPE.NON_LINED_UP );
1161 customizeRadioButtonMenuItem( _uniform_cladograms_rbmi,
1162 getOptions().getCladogramType() == CLADOGRAM_TYPE.TOTAL_NODE_SUM_DEP );
1163 customizeRadioButtonMenuItem( _ext_node_dependent_cladogram_rbmi,
1164 getOptions().getCladogramType() == CLADOGRAM_TYPE.EXT_NODE_SUM_DEP );
1165 customizeCheckBoxMenuItem( _show_overview_cbmi, getOptions().isShowOverview() );
1166 customizeCheckBoxMenuItem( _search_with_regex_cbmi, getOptions().isSearchWithRegex() );
1167 customizeCheckBoxMenuItem( _search_whole_words_only_cbmi, getOptions().isMatchWholeTermsOnly() );
1168 customizeCheckBoxMenuItem( _inverse_search_result_cbmi, getOptions().isInverseSearchResult() );
1169 customizeCheckBoxMenuItem( _show_confidence_stddev_cbmi, getOptions().isShowConfidenceStddev() );
1170 customizeCheckBoxMenuItem( _line_up_renderable_data_cbmi, getOptions().isLineUpRendarableNodeData() );
1171 customizeCheckBoxMenuItem( _right_line_up_domains_cbmi, getOptions().isRightLineUpDomains() );
1172 _jmenubar.add( _options_jmenu );
1175 void buildToolsMenu() {
1176 _tools_menu = MainFrame.createMenu( "Tools", getConfiguration() );
1177 _tools_menu.add( _confcolor_item = new JMenuItem( "Colorize Branches Depending on Confidence" ) );
1178 customizeJMenuItem( _confcolor_item );
1179 _tools_menu.add( _taxcolor_item = new JMenuItem( "Taxonomy Colorize Branches" ) );
1180 customizeJMenuItem( _taxcolor_item );
1181 _tools_menu.addSeparator();
1182 _tools_menu.add( _remove_visual_styles_item = new JMenuItem( "Delete All Visual Styles From Nodes" ) );
1183 _remove_visual_styles_item
1184 .setToolTipText( "To remove all node visual styles (fonts, colors) from the current phylogeny." );
1185 customizeJMenuItem( _remove_visual_styles_item );
1186 _tools_menu.add( _remove_branch_color_item = new JMenuItem( "Delete All Colors From Branches" ) );
1187 _remove_branch_color_item.setToolTipText( "To remove all branch color values from the current phylogeny." );
1188 customizeJMenuItem( _remove_branch_color_item );
1189 _tools_menu.addSeparator();
1190 _tools_menu.add( _midpoint_root_item = new JMenuItem( "Midpoint-Root" ) );
1191 customizeJMenuItem( _midpoint_root_item );
1192 _tools_menu.addSeparator();
1193 _tools_menu.add( _collapse_species_specific_subtrees = new JMenuItem( "Collapse Species-Specific Subtrees" ) );
1194 customizeJMenuItem( _collapse_species_specific_subtrees );
1195 _jmenubar.add( _tools_menu );
1198 void buildTypeMenu() {
1199 _type_menu = MainFrame.createMenu( MainFrame.TYPE_MENU_HEADER, getConfiguration() );
1200 _type_menu.add( _rectangular_type_cbmi = new JCheckBoxMenuItem( MainFrame.RECTANGULAR_TYPE_CBMI_LABEL ) );
1201 _type_menu.add( _euro_type_cbmi = new JCheckBoxMenuItem( MainFrame.EURO_TYPE_CBMI_LABEL ) );
1202 _type_menu.add( _rounded_type_cbmi = new JCheckBoxMenuItem( MainFrame.ROUNDED_TYPE_CBMI_LABEL ) );
1203 _type_menu.add( _curved_type_cbmi = new JCheckBoxMenuItem( MainFrame.CURVED_TYPE_CBMI_LABEL ) );
1204 _type_menu.add( _triangular_type_cbmi = new JCheckBoxMenuItem( MainFrame.TRIANGULAR_TYPE_CBMI_LABEL ) );
1205 _type_menu.add( _convex_type_cbmi = new JCheckBoxMenuItem( MainFrame.CONVEX_TYPE_CBMI_LABEL ) );
1206 _type_menu.add( _unrooted_type_cbmi = new JCheckBoxMenuItem( MainFrame.UNROOTED_TYPE_CBMI_LABEL ) );
1207 _type_menu.add( _circular_type_cbmi = new JCheckBoxMenuItem( MainFrame.CIRCULAR_TYPE_CBMI_LABEL ) );
1208 customizeCheckBoxMenuItem( _rectangular_type_cbmi, false );
1209 customizeCheckBoxMenuItem( _triangular_type_cbmi, false );
1210 customizeCheckBoxMenuItem( _euro_type_cbmi, false );
1211 customizeCheckBoxMenuItem( _rounded_type_cbmi, false );
1212 customizeCheckBoxMenuItem( _curved_type_cbmi, false );
1213 customizeCheckBoxMenuItem( _convex_type_cbmi, false );
1214 customizeCheckBoxMenuItem( _unrooted_type_cbmi, false );
1215 customizeCheckBoxMenuItem( _circular_type_cbmi, false );
1216 _unrooted_type_cbmi.setToolTipText( MainFrame.USE_MOUSEWHEEL_SHIFT_TO_ROTATE );
1217 _circular_type_cbmi.setToolTipText( MainFrame.USE_MOUSEWHEEL_SHIFT_TO_ROTATE );
1218 initializeTypeMenu( getOptions() );
1219 _jmenubar.add( _type_menu );
1222 void buildViewMenu() {
1223 _view_jmenu = MainFrame.createMenu( "View", getConfiguration() );
1225 .add( _display_basic_information_item = new JMenuItem( MainFrame.SHOW_BASIC_TREE_INFORMATION_LABEL ) );
1226 _view_jmenu.addSeparator();
1227 _view_jmenu.add( _view_as_XML_item = new JMenuItem( "as phyloXML" ) );
1228 _view_jmenu.add( _view_as_NH_item = new JMenuItem( "as Newick" ) );
1229 _view_jmenu.add( _view_as_nexus_item = new JMenuItem( "as Nexus" ) );
1230 customizeJMenuItem( _display_basic_information_item );
1231 customizeJMenuItem( _view_as_NH_item );
1232 customizeJMenuItem( _view_as_XML_item );
1233 customizeJMenuItem( _view_as_nexus_item );
1234 _jmenubar.add( _view_jmenu );
1237 void checkTextFrames() {
1238 if ( _textframes.size() > 5 ) {
1240 if ( _textframes.getFirst() != null ) {
1241 _textframes.getFirst().removeMe();
1244 _textframes.removeFirst();
1247 catch ( final NoSuchElementException e ) {
1253 void clearCurrentExternalNodesDataBuffer() {
1254 getCurrentTreePanel().clearCurrentExternalNodesDataBuffer();
1257 void customizeCheckBoxMenuItem( final JCheckBoxMenuItem item, final boolean is_selected ) {
1258 if ( item != null ) {
1259 item.setFont( MainFrame.menu_font );
1260 if ( !getConfiguration().isUseNativeUI() ) {
1261 item.setBackground( getConfiguration().getGuiMenuBackgroundColor() );
1262 item.setForeground( getConfiguration().getGuiMenuTextColor() );
1264 item.setSelected( is_selected );
1265 item.addActionListener( this );
1269 void customizeJMenuItem( final JMenuItem jmi ) {
1270 if ( jmi != null ) {
1271 jmi.setFont( MainFrame.menu_font );
1272 if ( !getConfiguration().isUseNativeUI() ) {
1273 jmi.setBackground( getConfiguration().getGuiMenuBackgroundColor() );
1274 jmi.setForeground( getConfiguration().getGuiMenuTextColor() );
1276 jmi.addActionListener( this );
1280 void displayBasicInformation() {
1281 if ( ( getMainPanel() != null ) && ( getMainPanel().getCurrentPhylogeny() != null )
1282 && !getMainPanel().getCurrentPhylogeny().isEmpty() ) {
1283 String title = "Basic Information";
1284 if ( !ForesterUtil.isEmpty( getMainPanel().getCurrentPhylogeny().getName() ) ) {
1285 title = title + " for \"" + _mainpanel.getCurrentPhylogeny().getName() + "\"";
1287 showTextFrame( AptxUtil.createBasicInformation( getMainPanel().getCurrentPhylogeny(), null ), title );
1291 void executeGSDI() {
1292 if ( !isOKforSDI( false, true ) ) {
1295 if ( !_mainpanel.getCurrentPhylogeny().isRooted() ) {
1296 JOptionPane.showMessageDialog( this,
1297 "Gene tree is not rooted.",
1298 "Cannot execute GSDI",
1299 JOptionPane.ERROR_MESSAGE );
1302 final Phylogeny gene_tree = _mainpanel.getCurrentPhylogeny().copy();
1303 gene_tree.setAllNodesToNotCollapse();
1304 gene_tree.recalculateNumberOfExternalDescendants( false );
1306 final Phylogeny species_tree = _species_tree.copy();
1308 gsdi = new GSDI( gene_tree, species_tree, false, true, true, true );
1310 catch ( final SDIException e ) {
1311 JOptionPane.showMessageDialog( this,
1312 e.getLocalizedMessage(),
1313 "Error during GSDI",
1314 JOptionPane.ERROR_MESSAGE );
1317 catch ( final Exception e ) {
1318 AptxUtil.unexpectedException( e );
1321 gene_tree.setRerootable( false );
1322 gene_tree.clearHashIdToNodeMap();
1323 gene_tree.recalculateNumberOfExternalDescendants( true );
1324 _mainpanel.addPhylogenyInNewTab( gene_tree, getConfiguration(), "gene tree", null );
1325 getMainPanel().getControlPanel().setShowEvents( true );
1327 final int selected = _mainpanel.getTabbedPane().getSelectedIndex();
1328 _mainpanel.addPhylogenyInNewTab( species_tree, getConfiguration(), "species tree", null );
1330 _mainpanel.getTabbedPane().setSelectedIndex( selected );
1332 _mainpanel.getCurrentTreePanel().setEdited( true );
1333 final int poly = PhylogenyMethods.countNumberOfPolytomies( species_tree );
1334 if ( gsdi.getStrippedExternalGeneTreeNodes().size() > 0 ) {
1335 JOptionPane.showMessageDialog( this,
1336 "Duplications: " + gsdi.getDuplicationsSum() + "\n"
1337 + "Potential duplications: "
1338 + gsdi.getSpeciationOrDuplicationEventsSum() + "\n"
1339 + "Speciations: " + gsdi.getSpeciationsSum() + "\n"
1340 + "Stripped gene tree nodes: "
1341 + gsdi.getStrippedExternalGeneTreeNodes().size() + "\n"
1342 + "Taxonomy linkage based on: " + gsdi.getTaxCompBase() + "\n"
1343 + "Number of polytomies in species tree used: " + poly + "\n",
1344 "GSDI successfully completed",
1345 JOptionPane.WARNING_MESSAGE );
1348 JOptionPane.showMessageDialog( this,
1349 "Duplications: " + gsdi.getDuplicationsSum() + "\n"
1350 + "Potential duplications: "
1351 + gsdi.getSpeciationOrDuplicationEventsSum() + "\n"
1352 + "Speciations: " + gsdi.getSpeciationsSum() + "\n"
1353 + "Stripped gene tree nodes: "
1354 + gsdi.getStrippedExternalGeneTreeNodes().size() + "\n"
1355 + "Taxonomy linkage based on: " + gsdi.getTaxCompBase() + "\n"
1356 + "Number of polytomies in species tree used: " + poly + "\n",
1357 "GSDI successfully completed",
1358 JOptionPane.INFORMATION_MESSAGE );
1362 void executeGSDIR() {
1363 if ( !isOKforSDI( false, false ) ) {
1366 final int p = PhylogenyMethods.countNumberOfPolytomies( _mainpanel.getCurrentPhylogeny() );
1368 && !( ( p == 1 ) && ( _mainpanel.getCurrentPhylogeny().getRoot().getNumberOfDescendants() == 3 ) ) ) {
1369 JOptionPane.showMessageDialog( this,
1370 "Gene tree is not completely binary",
1371 "Cannot execute GSDI",
1372 JOptionPane.ERROR_MESSAGE );
1375 final Phylogeny gene_tree = _mainpanel.getCurrentPhylogeny().copy();
1376 gene_tree.setAllNodesToNotCollapse();
1377 gene_tree.recalculateNumberOfExternalDescendants( false );
1379 final Phylogeny species_tree = _species_tree.copy();
1381 gsdir = new GSDIR( gene_tree, species_tree, true, true, true );
1383 catch ( final SDIException e ) {
1384 JOptionPane.showMessageDialog( this,
1385 e.getLocalizedMessage(),
1386 "Error during GSDIR",
1387 JOptionPane.ERROR_MESSAGE );
1390 catch ( final Exception e ) {
1391 AptxUtil.unexpectedException( e );
1394 final Phylogeny result_gene_tree = gsdir.getMinDuplicationsSumGeneTree();
1395 result_gene_tree.setRerootable( false );
1396 result_gene_tree.clearHashIdToNodeMap();
1397 result_gene_tree.recalculateNumberOfExternalDescendants( true );
1398 PhylogenyMethods.orderAppearance( result_gene_tree.getRoot(), true, true, DESCENDANT_SORT_PRIORITY.NODE_NAME );
1399 _mainpanel.addPhylogenyInNewTab( result_gene_tree, getConfiguration(), "gene tree", null );
1400 getMainPanel().getControlPanel().setShowEvents( true );
1402 final int selected = _mainpanel.getTabbedPane().getSelectedIndex();
1403 _mainpanel.addPhylogenyInNewTab( species_tree, getConfiguration(), "species tree", null );
1405 _mainpanel.getTabbedPane().setSelectedIndex( selected );
1407 _mainpanel.getCurrentTreePanel().setEdited( true );
1408 final int poly = PhylogenyMethods.countNumberOfPolytomies( species_tree );
1409 if ( gsdir.getStrippedExternalGeneTreeNodes().size() > 0 ) {
1410 JOptionPane.showMessageDialog( this,
1411 "Minimal duplications: " + gsdir.getMinDuplicationsSum() + "\n"
1412 + "Speciations: " + gsdir.getSpeciationsSum() + "\n"
1413 + "Stripped gene tree nodes: "
1414 + gsdir.getStrippedExternalGeneTreeNodes().size() + "\n"
1415 + "Taxonomy linkage based on: " + gsdir.getTaxCompBase() + "\n"
1416 + "Number of polytomies in species tree used: " + poly + "\n",
1417 "GSDIR successfully completed",
1418 JOptionPane.WARNING_MESSAGE );
1421 JOptionPane.showMessageDialog( this,
1422 "Minimal duplications: " + gsdir.getMinDuplicationsSum() + "\n"
1423 + "Speciations: " + gsdir.getSpeciationsSum() + "\n"
1424 + "Stripped gene tree nodes: "
1425 + gsdir.getStrippedExternalGeneTreeNodes().size() + "\n"
1426 + "Taxonomy linkage based on: " + gsdir.getTaxCompBase() + "\n"
1427 + "Number of polytomies in species tree used: " + poly + "\n",
1428 "GSDIR successfully completed",
1429 JOptionPane.INFORMATION_MESSAGE );
1433 Configuration getConfiguration() {
1434 return _configuration;
1437 TreePanel getCurrentTreePanel() {
1438 return getMainPanel().getCurrentTreePanel();
1441 JCheckBoxMenuItem getlabelDirectionCbmi() {
1442 return _label_direction_cbmi;
1445 Options getOtions() {
1449 void initializeTypeMenu( final Options options ) {
1450 setTypeMenuToAllUnselected();
1452 switch ( options.getPhylogenyGraphicsType() ) {
1454 _convex_type_cbmi.setSelected( true );
1457 _curved_type_cbmi.setSelected( true );
1460 _euro_type_cbmi.setSelected( true );
1463 _rounded_type_cbmi.setSelected( true );
1466 _triangular_type_cbmi.setSelected( true );
1469 _unrooted_type_cbmi.setSelected( true );
1472 _circular_type_cbmi.setSelected( true );
1475 _rectangular_type_cbmi.setSelected( true );
1479 catch ( final NullPointerException np ) {
1480 // In all likelihood, this is caused by menu-less display.
1484 boolean isOKforSDI( final boolean species_tree_has_to_binary, final boolean gene_tree_has_to_binary ) {
1485 if ( ( _mainpanel.getCurrentPhylogeny() == null ) || _mainpanel.getCurrentPhylogeny().isEmpty() ) {
1488 else if ( ( _species_tree == null ) || _species_tree.isEmpty() ) {
1489 JOptionPane.showMessageDialog( this,
1490 "No species tree loaded",
1491 "Cannot execute GSDI",
1492 JOptionPane.ERROR_MESSAGE );
1495 else if ( species_tree_has_to_binary && !_species_tree.isCompletelyBinary() ) {
1496 JOptionPane.showMessageDialog( this,
1497 "Species tree is not completely binary",
1498 "Cannot execute GSDI",
1499 JOptionPane.ERROR_MESSAGE );
1502 else if ( gene_tree_has_to_binary && !_mainpanel.getCurrentPhylogeny().isCompletelyBinary() ) {
1503 JOptionPane.showMessageDialog( this,
1504 "Gene tree is not completely binary",
1505 "Cannot execute GSDI",
1506 JOptionPane.ERROR_MESSAGE );
1514 boolean isSubtreeDisplayed() {
1515 if ( getCurrentTreePanel() != null ) {
1516 if ( getCurrentTreePanel().isCurrentTreeIsSubtree() ) {
1518 .showMessageDialog( this,
1519 "This operation can only be performed on a complete tree, not on the currently displayed sub-tree only.",
1520 "Operation can not be exectuted on a sub-tree",
1521 JOptionPane.WARNING_MESSAGE );
1528 void removeAllTextFrames() {
1529 for( final TextFrame tf : _textframes ) {
1534 _textframes.clear();
1537 void setConfiguration( final Configuration configuration ) {
1538 _configuration = configuration;
1541 void setOptions( final Options options ) {
1545 void setSelectedTypeInTypeMenu( final PHYLOGENY_GRAPHICS_TYPE type ) {
1546 setTypeMenuToAllUnselected();
1550 _circular_type_cbmi.setSelected( true );
1553 _convex_type_cbmi.setSelected( true );
1556 _curved_type_cbmi.setSelected( true );
1559 _euro_type_cbmi.setSelected( true );
1562 _rounded_type_cbmi.setSelected( true );
1565 _rectangular_type_cbmi.setSelected( true );
1568 _triangular_type_cbmi.setSelected( true );
1571 _unrooted_type_cbmi.setSelected( true );
1574 throw new IllegalArgumentException( "unknown type: " + type );
1577 catch ( final NullPointerException np ) {
1578 // In all likelihood, this is caused by menu-less display.
1582 void setTypeMenuToAllUnselected() {
1583 if ( _convex_type_cbmi != null ) {
1584 _convex_type_cbmi.setSelected( false );
1586 if ( _curved_type_cbmi != null ) {
1587 _curved_type_cbmi.setSelected( false );
1589 if ( _euro_type_cbmi != null ) {
1590 _euro_type_cbmi.setSelected( false );
1592 if ( _rounded_type_cbmi != null ) {
1593 _rounded_type_cbmi.setSelected( false );
1595 if ( _triangular_type_cbmi != null ) {
1596 _triangular_type_cbmi.setSelected( false );
1598 if ( _rectangular_type_cbmi != null ) {
1599 _rectangular_type_cbmi.setSelected( false );
1601 if ( _unrooted_type_cbmi != null ) {
1602 _unrooted_type_cbmi.setSelected( false );
1604 if ( _circular_type_cbmi != null ) {
1605 _circular_type_cbmi.setSelected( false );
1610 _mainpanel.getControlPanel().showWhole();
1613 void switchColors() {
1614 final TreeColorSet colorset = getMainPanel().getCurrentTreePanel().getTreeColorSet();
1615 final ColorSchemeChooser csc = new ColorSchemeChooser( getMainPanel(), colorset );
1616 csc.setVisible( true );
1617 getMainPanel().setTreeColorSet( colorset );
1620 void typeChanged( final Object o ) {
1621 updateTypeCheckboxes( getOptions(), o );
1622 updateOptions( getOptions() );
1623 if ( getCurrentTreePanel() != null ) {
1624 final PHYLOGENY_GRAPHICS_TYPE previous_type = getCurrentTreePanel().getPhylogenyGraphicsType();
1625 final PHYLOGENY_GRAPHICS_TYPE new_type = getOptions().getPhylogenyGraphicsType();
1626 if ( ( ( previous_type == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) && ( new_type != PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) )
1627 || ( ( previous_type == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) && ( new_type != PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) )
1628 || ( ( previous_type != PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) && ( new_type == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) )
1629 || ( ( previous_type != PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) && ( new_type == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) ) ) {
1630 getCurrentTreePanel().getControlPanel().showWhole();
1632 if ( getCurrentTreePanel().isPhyHasBranchLengths() && ( new_type != PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) ) {
1633 getCurrentTreePanel().getControlPanel().setDrawPhylogramEnabled( true );
1636 getCurrentTreePanel().getControlPanel().setDrawPhylogramEnabled( false );
1638 getCurrentTreePanel().setPhylogenyGraphicsType( getOptions().getPhylogenyGraphicsType() );
1639 MainFrame.updateScreenTextAntialias( getMainPanel().getTreePanels() );
1643 void updateOptions( final Options options ) {
1644 options.setAntialiasScreen( ( _screen_antialias_cbmi != null ) && _screen_antialias_cbmi.isSelected() );
1645 options.setBackgroundColorGradient( ( _background_gradient_cbmi != null )
1646 && _background_gradient_cbmi.isSelected() );
1647 options.setShowDomainLabels( ( _show_domain_labels != null ) && _show_domain_labels.isSelected() );
1648 options.setShowAnnotationRefSource( ( _show_annotation_ref_source != null )
1649 && _show_annotation_ref_source.isSelected() );
1650 options.setAbbreviateScientificTaxonNames( ( _abbreviate_scientific_names != null )
1651 && _abbreviate_scientific_names.isSelected() );
1652 options.setColorLabelsSameAsParentBranch( ( _color_labels_same_as_parent_branch != null )
1653 && _color_labels_same_as_parent_branch.isSelected() );
1654 options.setShowDefaultNodeShapesInternal( ( _show_default_node_shapes_internal_cbmi != null )
1655 && _show_default_node_shapes_internal_cbmi.isSelected() );
1656 options.setShowDefaultNodeShapesExternal( ( _show_default_node_shapes_external_cbmi != null )
1657 && _show_default_node_shapes_external_cbmi.isSelected() );
1658 options.setShowDefaultNodeShapesForMarkedNodes( ( _show_default_node_shapes_for_marked_cbmi != null )
1659 && _show_default_node_shapes_for_marked_cbmi.isSelected() );
1660 if ( ( _non_lined_up_cladograms_rbmi != null ) && ( _non_lined_up_cladograms_rbmi.isSelected() ) ) {
1661 options.setCladogramType( CLADOGRAM_TYPE.NON_LINED_UP );
1663 else if ( ( _uniform_cladograms_rbmi != null ) && ( _uniform_cladograms_rbmi.isSelected() ) ) {
1664 options.setCladogramType( CLADOGRAM_TYPE.TOTAL_NODE_SUM_DEP );
1666 else if ( ( _ext_node_dependent_cladogram_rbmi != null ) && ( _ext_node_dependent_cladogram_rbmi.isSelected() ) ) {
1667 options.setCladogramType( CLADOGRAM_TYPE.EXT_NODE_SUM_DEP );
1669 options.setSearchCaseSensitive( ( _search_case_senstive_cbmi != null )
1670 && _search_case_senstive_cbmi.isSelected() );
1671 if ( ( _show_scale_cbmi != null ) && _show_scale_cbmi.isEnabled() ) {
1672 options.setShowScale( _show_scale_cbmi.isSelected() );
1674 if ( _label_direction_cbmi != null ) {
1675 if ( _label_direction_cbmi.isSelected() ) {
1676 options.setNodeLabelDirection( NODE_LABEL_DIRECTION.RADIAL );
1679 options.setNodeLabelDirection( NODE_LABEL_DIRECTION.HORIZONTAL );
1682 options.setShowOverview( ( _show_overview_cbmi != null ) && _show_overview_cbmi.isSelected() );
1683 options.setShowConfidenceStddev( ( _show_confidence_stddev_cbmi != null )
1684 && _show_confidence_stddev_cbmi.isSelected() );
1685 options.setMatchWholeTermsOnly( ( _search_whole_words_only_cbmi != null )
1686 && _search_whole_words_only_cbmi.isSelected() );
1687 options.setSearchWithRegex( ( _search_with_regex_cbmi != null ) && _search_with_regex_cbmi.isSelected() );
1688 options.setInverseSearchResult( ( _inverse_search_result_cbmi != null )
1689 && _inverse_search_result_cbmi.isSelected() );
1690 if ( ( _rectangular_type_cbmi != null ) && _rectangular_type_cbmi.isSelected() ) {
1691 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR );
1693 else if ( ( _triangular_type_cbmi != null ) && _triangular_type_cbmi.isSelected() ) {
1694 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.TRIANGULAR );
1696 else if ( ( _curved_type_cbmi != null ) && _curved_type_cbmi.isSelected() ) {
1697 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CURVED );
1699 else if ( ( _convex_type_cbmi != null ) && _convex_type_cbmi.isSelected() ) {
1700 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CONVEX );
1702 else if ( ( _euro_type_cbmi != null ) && _euro_type_cbmi.isSelected() ) {
1703 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE );
1705 else if ( ( _rounded_type_cbmi != null ) && _rounded_type_cbmi.isSelected() ) {
1706 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.ROUNDED );
1708 else if ( ( _unrooted_type_cbmi != null ) && _unrooted_type_cbmi.isSelected() ) {
1709 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.UNROOTED );
1711 else if ( ( _circular_type_cbmi != null ) && _circular_type_cbmi.isSelected() ) {
1712 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CIRCULAR );
1714 if ( ( _color_by_taxonomic_group_cbmi != null ) && _color_by_taxonomic_group_cbmi.isEnabled() ) {
1715 options.setColorByTaxonomicGroup( _color_by_taxonomic_group_cbmi.isSelected() );
1717 if ( ( _right_line_up_domains_cbmi != null ) && _right_line_up_domains_cbmi.isEnabled() ) {
1718 options.setRightLineUpDomains( _right_line_up_domains_cbmi.isSelected() );
1720 if ( ( _line_up_renderable_data_cbmi != null ) && _line_up_renderable_data_cbmi.isEnabled() ) {
1721 options.setLineUpRendarableNodeData( _line_up_renderable_data_cbmi.isSelected() );
1725 void updateTypeCheckboxes( final Options options, final Object o ) {
1726 setTypeMenuToAllUnselected();
1727 ( ( JCheckBoxMenuItem ) o ).setSelected( true );
1730 void viewAsNexus() {
1731 if ( ( getMainPanel().getCurrentPhylogeny() != null ) && !getMainPanel().getCurrentPhylogeny().isEmpty() ) {
1732 String title = "Nexus";
1733 if ( !ForesterUtil.isEmpty( getMainPanel().getCurrentPhylogeny().getName() ) ) {
1734 title = "\"" + getMainPanel().getCurrentPhylogeny().getName() + "\" in " + title;
1736 showTextFrame( getMainPanel().getCurrentPhylogeny().toNexus( getOptions()
1737 .getNhConversionSupportValueStyle() ),
1743 if ( ( getMainPanel().getCurrentPhylogeny() != null ) && !getMainPanel().getCurrentPhylogeny().isEmpty() ) {
1744 String title = "New Hampshire";
1745 if ( !ForesterUtil.isEmpty( getMainPanel().getCurrentPhylogeny().getName() ) ) {
1746 title = "\"" + getMainPanel().getCurrentPhylogeny().getName() + "\" in " + title;
1748 showTextFrame( getMainPanel().getCurrentPhylogeny().toNewHampshire( getOptions()
1749 .getNhConversionSupportValueStyle() ),
1755 if ( ( getMainPanel().getCurrentPhylogeny() != null ) && !getMainPanel().getCurrentPhylogeny().isEmpty() ) {
1756 String title = "phyloXML";
1757 if ( !ForesterUtil.isEmpty( getMainPanel().getCurrentPhylogeny().getName() ) ) {
1758 title = "\"" + getMainPanel().getCurrentPhylogeny().getName() + "\" in " + title;
1760 showTextFrame( getMainPanel().getCurrentPhylogeny().toPhyloXML( 0 ), title );
1764 private void chooseFont() {
1765 final FontChooser fc = new FontChooser();
1766 fc.setFont( getMainPanel().getTreeFontSet().getLargeFont() );
1767 fc.showDialog( this, "Select the Base Font" );
1768 getMainPanel().getTreeFontSet().setBaseFont( fc.getFont() );
1771 private void chooseMinimalConfidence() {
1772 final String s = ( String ) JOptionPane
1773 .showInputDialog( this,
1774 "Please the minimum for confidence values to be displayed.\n" + "[current value: "
1775 + getOptions().getMinConfidenceValue() + "]\n",
1776 "Minimal Confidence Value",
1777 JOptionPane.QUESTION_MESSAGE,
1780 getOptions().getMinConfidenceValue() );
1781 if ( !ForesterUtil.isEmpty( s ) ) {
1782 boolean success = true;
1784 final String m_str = s.trim();
1785 if ( !ForesterUtil.isEmpty( m_str ) ) {
1787 m = Double.parseDouble( m_str );
1789 catch ( final Exception ex ) {
1796 if ( success && ( m >= 0.0 ) ) {
1797 getOptions().setMinConfidenceValue( m );
1802 private void customizeRadioButtonMenuItem( final JRadioButtonMenuItem item, final boolean is_selected ) {
1803 if ( item != null ) {
1804 item.setFont( MainFrame.menu_font );
1805 if ( !getConfiguration().isUseNativeUI() ) {
1806 item.setBackground( getConfiguration().getGuiMenuBackgroundColor() );
1807 item.setForeground( getConfiguration().getGuiMenuTextColor() );
1809 item.setSelected( is_selected );
1810 item.addActionListener( this );
1814 MainPanel getMainPanel() {
1818 private Phylogeny getSpeciesTree() {
1819 return _species_tree;
1822 private boolean isScreenAntialias() {
1826 private void removeBranchColors() {
1827 if ( getMainPanel().getCurrentPhylogeny() != null ) {
1828 AptxUtil.removeBranchColors( getMainPanel().getCurrentPhylogeny() );
1832 private void removeVisualStyles() {
1833 if ( getMainPanel().getCurrentPhylogeny() != null ) {
1834 AptxUtil.removeVisualStyles( getMainPanel().getCurrentPhylogeny() );
1838 private void setMainPanel( final MainPanelApplets main_panel ) {
1839 _mainpanel = main_panel;
1842 private void setSpeciesTree( final Phylogeny species_tree ) {
1843 _species_tree = species_tree;
1846 private void setupUI() {
1848 if ( getConfiguration().isUseNativeUI() ) {
1849 UIManager.setLookAndFeel( UIManager.getSystemLookAndFeelClassName() );
1852 UIManager.setLookAndFeel( UIManager.getCrossPlatformLookAndFeelClassName() );
1855 catch ( final UnsupportedLookAndFeelException e ) {
1856 AptxUtil.dieWithSystemError( "UnsupportedLookAndFeelException: " + e.toString() );
1858 catch ( final ClassNotFoundException e ) {
1859 AptxUtil.dieWithSystemError( "ClassNotFoundException: " + e.toString() );
1861 catch ( final InstantiationException e ) {
1862 AptxUtil.dieWithSystemError( "InstantiationException: " + e.toString() );
1864 catch ( final IllegalAccessException e ) {
1865 AptxUtil.dieWithSystemError( "IllegalAccessException: " + e.toString() );
1867 catch ( final Exception e ) {
1868 AptxUtil.dieWithSystemError( e.toString() );
1872 static void setupScreenTextAntialias( final List<TreePanel> treepanels, final boolean antialias ) {
1873 for( final TreePanel tree_panel : treepanels ) {
1874 tree_panel.setTextAntialias();