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.JFileChooser;
22 import javax.swing.JMenu;
23 import javax.swing.JMenuBar;
24 import javax.swing.JMenuItem;
25 import javax.swing.JOptionPane;
26 import javax.swing.JRadioButtonMenuItem;
27 import javax.swing.UIManager;
28 import javax.swing.UnsupportedLookAndFeelException;
29 import javax.swing.event.ChangeEvent;
30 import javax.swing.event.ChangeListener;
32 import org.apache.commons.codec.binary.Base64;
33 import org.forester.archaeopteryx.AptxUtil.GraphicsExportType;
34 import org.forester.archaeopteryx.Options.CLADOGRAM_TYPE;
35 import org.forester.archaeopteryx.Options.NODE_LABEL_DIRECTION;
36 import org.forester.archaeopteryx.Options.PHYLOGENY_GRAPHICS_TYPE;
37 import org.forester.io.parsers.nhx.NHXParser.TAXONOMY_EXTRACTION;
38 import org.forester.phylogeny.Phylogeny;
39 import org.forester.phylogeny.PhylogenyMethods;
40 import org.forester.phylogeny.PhylogenyMethods.DESCENDANT_SORT_PRIORITY;
41 import org.forester.phylogeny.data.SequenceRelation;
42 import org.forester.sdi.GSDI;
43 import org.forester.sdi.GSDIR;
44 import org.forester.sdi.SDIException;
45 import org.forester.util.ForesterConstants;
46 import org.forester.util.ForesterUtil;
47 import org.forester.util.WindowsUtils;
50 // <applet archive="forester.jar"
51 // code="org.forester.archaeopteryx.ArchaeopteryxE.class"
52 // codebase="http://www.myserver.org/path/to/forester"
55 // alt="ArchaeopteryxE is not working on your system (requires at least Sun Java 1.5)!">
56 // <param name="url_of_tree_to_load"
57 // value="http://www.myserver.org/examples/data/apaf.xml">
58 // <param name="config_file"
59 // value="http://www.myserver.org/examples/config/config_file.txt">
61 public class ArchaeopteryxE extends JApplet implements ActionListener {
63 private final static String NAME = "ArchaeopteryxE";
64 private static final long serialVersionUID = -1220055577935759443L;
65 private Configuration _configuration;
66 private MainPanel _mainpanel;
67 private JMenuBar _jmenubar;
68 private JMenu _options_jmenu;
69 private JMenu _font_size_menu;
70 private JMenuItem _super_tiny_fonts_mi;
71 private JMenuItem _tiny_fonts_mi;
72 private JMenuItem _small_fonts_mi;
73 private JMenuItem _medium_fonts_mi;
74 private JMenuItem _large_fonts_mi;
75 private JMenu _tools_menu;
76 private JMenuItem _taxcolor_item;
77 private JMenuItem _confcolor_item;
78 private JMenuItem _midpoint_root_item;
79 private JMenu _view_jmenu;
80 private JMenuItem _view_as_XML_item;
81 private JMenuItem _view_as_NH_item;
82 private JMenuItem _view_as_nexus_item;
83 private JMenuItem _display_basic_information_item;
84 private JMenu _type_menu;
85 private JCheckBoxMenuItem _rectangular_type_cbmi;
86 private JCheckBoxMenuItem _triangular_type_cbmi;
87 private JCheckBoxMenuItem _curved_type_cbmi;
88 private JCheckBoxMenuItem _convex_type_cbmi;
89 private JCheckBoxMenuItem _euro_type_cbmi;
90 private JCheckBoxMenuItem _rounded_type_cbmi;
91 private JCheckBoxMenuItem _unrooted_type_cbmi;
92 private JCheckBoxMenuItem _circular_type_cbmi;
93 private JMenuItem _help_item;
94 private JMenuItem _about_item;
95 private JMenu _help_jmenu;
96 private JMenuItem _website_item;
97 private JMenuItem _phyloxml_website_item;
98 private JMenuItem _phyloxml_ref_item;
99 private JMenuItem _aptx_ref_item;
100 private JMenuItem _remove_branch_color_item;
101 private JMenuItem _remove_visual_styles_item;
102 private JCheckBoxMenuItem _show_domain_labels;
103 private JCheckBoxMenuItem _show_annotation_ref_source;
104 private JCheckBoxMenuItem _color_labels_same_as_parent_branch;
105 private JCheckBoxMenuItem _abbreviate_scientific_names;
106 private JCheckBoxMenuItem _screen_antialias_cbmi;
107 private JCheckBoxMenuItem _background_gradient_cbmi;
108 private JCheckBoxMenuItem _color_by_taxonomic_group_cbmi;
109 private JRadioButtonMenuItem _non_lined_up_cladograms_rbmi;
110 private JRadioButtonMenuItem _uniform_cladograms_rbmi;
111 private JRadioButtonMenuItem _ext_node_dependent_cladogram_rbmi;
112 private Options _options;
113 private JMenuItem _choose_font_mi;
114 private JMenuItem _switch_colors_mi;
115 JCheckBoxMenuItem _label_direction_cbmi;
116 private JCheckBoxMenuItem _show_scale_cbmi;
117 private JCheckBoxMenuItem _search_case_senstive_cbmi;
118 private JCheckBoxMenuItem _search_whole_words_only_cbmi;
119 private JCheckBoxMenuItem _inverse_search_result_cbmi;
120 private JCheckBoxMenuItem _search_with_regex_cbmi;
121 private JCheckBoxMenuItem _show_overview_cbmi;
122 private JMenuItem _choose_minimal_confidence_mi;
123 private JMenuItem _collapse_species_specific_subtrees;
124 private JMenuItem _overview_placment_mi;
125 private ButtonGroup _radio_group_1;
126 private JCheckBoxMenuItem _show_default_node_shapes_internal_cbmi;
127 private JCheckBoxMenuItem _show_default_node_shapes_external_cbmi;
128 private JCheckBoxMenuItem _show_default_node_shapes_for_marked_cbmi;
129 private JMenuItem _cycle_node_shape_mi;
130 private JMenuItem _cycle_node_fill_mi;
131 private JMenuItem _choose_node_size_mi;
132 private JCheckBoxMenuItem _show_confidence_stddev_cbmi;
133 private final LinkedList<TextFrame> _textframes = new LinkedList<TextFrame>();
134 private JMenu _analysis_menu;
135 private JMenuItem _gsdi_item;
136 private JMenuItem _gsdir_item;
137 private Phylogeny _species_tree;
138 private JCheckBoxMenuItem _right_line_up_domains_cbmi;
139 private JCheckBoxMenuItem _line_up_renderable_data_cbmi;
141 private JMenuItem _save_item;
142 private JMenuItem _print_item;
143 private JMenuItem _write_to_pdf_item;
144 private JMenuItem _write_to_jpg_item;
145 private JMenuItem _write_to_gif_item;
146 private JMenuItem _write_to_tif_item;
147 private JMenuItem _write_to_png_item;
148 private JMenuItem _write_to_bmp_item;
149 private JMenu _file_jmenu;
150 private JFileChooser _writetopdf_filechooser;
151 private File _current_dir;
152 private JFileChooser _save_filechooser;
153 private JFileChooser _writetographics_filechooser;
154 private JCheckBoxMenuItem _graphics_export_visible_only_cbmi;
155 private JCheckBoxMenuItem _antialias_print_cbmi;
156 private JCheckBoxMenuItem _print_black_and_white_cbmi;
157 private JCheckBoxMenuItem _print_using_actual_size_cbmi;
158 private JCheckBoxMenuItem _graphics_export_using_actual_size_cbmi;
159 private JMenuItem _print_size_mi;
160 private JMenuItem _choose_pdf_width_mi;
163 public void actionPerformed( final ActionEvent e ) {
164 final Object o = e.getSource();
165 if ( o == _midpoint_root_item ) {
166 getMainPanel().getCurrentTreePanel().midpointRoot();
168 else if ( o == _gsdi_item ) {
169 if ( isSubtreeDisplayed() ) {
174 else if ( o == _gsdir_item ) {
175 if ( isSubtreeDisplayed() ) {
180 else if ( o == _taxcolor_item ) {
181 getMainPanel().getCurrentTreePanel().taxColor();
183 else if ( o == _confcolor_item ) {
184 getMainPanel().getCurrentTreePanel().confColor();
186 else if ( o == _collapse_species_specific_subtrees ) {
187 if ( getCurrentTreePanel() != null ) {
188 getCurrentTreePanel().collapseSpeciesSpecificSubtrees();
191 else if ( o == _remove_branch_color_item ) {
192 removeBranchColors();
194 else if ( o == _remove_visual_styles_item ) {
195 removeVisualStyles();
197 else if ( o == _switch_colors_mi ) {
200 else if ( o == _display_basic_information_item ) {
201 displayBasicInformation();
203 else if ( o == _view_as_NH_item ) {
206 else if ( o == _view_as_XML_item ) {
209 else if ( o == _view_as_nexus_item ) {
212 else if ( o == _super_tiny_fonts_mi ) {
213 if ( getCurrentTreePanel() != null ) {
214 getCurrentTreePanel().setSuperTinyFonts();
215 getCurrentTreePanel().repaint();
218 else if ( o == _tiny_fonts_mi ) {
219 if ( getCurrentTreePanel() != null ) {
220 getCurrentTreePanel().setTinyFonts();
221 getCurrentTreePanel().repaint();
224 else if ( o == _small_fonts_mi ) {
225 if ( getCurrentTreePanel() != null ) {
226 getCurrentTreePanel().setSmallFonts();
227 getCurrentTreePanel().repaint();
230 else if ( o == _medium_fonts_mi ) {
231 if ( getCurrentTreePanel() != null ) {
232 getCurrentTreePanel().setMediumFonts();
233 getCurrentTreePanel().repaint();
236 else if ( o == _large_fonts_mi ) {
237 if ( getCurrentTreePanel() != null ) {
238 getCurrentTreePanel().setLargeFonts();
239 getCurrentTreePanel().repaint();
242 else if ( o == _choose_font_mi ) {
245 else if ( o == _choose_minimal_confidence_mi ) {
246 chooseMinimalConfidence();
248 else if ( o == _choose_node_size_mi ) {
249 MainFrame.chooseNodeSize( getOptions(), this );
251 else if ( o == _overview_placment_mi ) {
252 MainFrame.cycleOverview( getOptions(), getCurrentTreePanel() );
254 else if ( o == _cycle_node_fill_mi ) {
255 MainFrame.cycleNodeFill( getOptions() );
257 else if ( o == _cycle_node_shape_mi ) {
258 MainFrame.cycleNodeShape( getOptions() );
260 else if ( o == _non_lined_up_cladograms_rbmi ) {
261 updateOptions( getOptions() );
262 _mainpanel.getControlPanel().showWhole();
264 else if ( o == _uniform_cladograms_rbmi ) {
265 updateOptions( getOptions() );
266 _mainpanel.getControlPanel().showWhole();
268 else if ( o == _ext_node_dependent_cladogram_rbmi ) {
269 updateOptions( getOptions() );
270 _mainpanel.getControlPanel().showWhole();
272 else if ( o == _search_case_senstive_cbmi ) {
273 updateOptions( getOptions() );
274 getMainPanel().getControlPanel().search0();
275 getMainPanel().getControlPanel().search1();
277 else if ( o == _search_whole_words_only_cbmi ) {
278 if ( ( _search_with_regex_cbmi != null ) && _search_whole_words_only_cbmi.isSelected() ) {
279 _search_with_regex_cbmi.setSelected( false );
281 updateOptions( getOptions() );
282 getMainPanel().getControlPanel().search0();
283 getMainPanel().getControlPanel().search1();
285 else if ( o == _inverse_search_result_cbmi ) {
286 updateOptions( getOptions() );
287 getMainPanel().getControlPanel().search0();
288 getMainPanel().getControlPanel().search1();
290 else if ( o == _search_with_regex_cbmi ) {
291 if ( ( _search_whole_words_only_cbmi != null ) && _search_with_regex_cbmi.isSelected() ) {
292 _search_whole_words_only_cbmi.setSelected( false );
294 if ( ( _search_case_senstive_cbmi != null ) && _search_with_regex_cbmi.isSelected() ) {
295 _search_case_senstive_cbmi.setSelected( true );
297 updateOptions( getOptions() );
298 getMainPanel().getControlPanel().search0();
299 getMainPanel().getControlPanel().search1();
301 else if ( o == _show_scale_cbmi ) {
302 updateOptions( getOptions() );
304 else if ( o == _show_confidence_stddev_cbmi ) {
305 updateOptions( getOptions() );
307 else if ( o == _label_direction_cbmi ) {
308 updateOptions( getOptions() );
310 else if ( o == _abbreviate_scientific_names ) {
311 updateOptions( getOptions() );
313 else if ( o == _show_overview_cbmi ) {
314 updateOptions( getOptions() );
315 if ( getCurrentTreePanel() != null ) {
316 getCurrentTreePanel().updateOvSizes();
319 else if ( ( o == _rectangular_type_cbmi ) || ( o == _triangular_type_cbmi ) || ( o == _curved_type_cbmi )
320 || ( o == _convex_type_cbmi ) || ( o == _rounded_type_cbmi ) || ( o == _euro_type_cbmi )
321 || ( o == _unrooted_type_cbmi ) || ( o == _circular_type_cbmi ) ) {
324 else if ( o == _screen_antialias_cbmi ) {
325 updateOptions( getOptions() );
326 setupScreenTextAntialias( getMainPanel().getTreePanels(), isScreenAntialias() );
328 else if ( o == _background_gradient_cbmi ) {
329 updateOptions( getOptions() );
331 else if ( o == _show_domain_labels ) {
332 updateOptions( getOptions() );
334 else if ( o == _color_labels_same_as_parent_branch ) {
335 updateOptions( getOptions() );
337 else if ( o == _show_default_node_shapes_internal_cbmi ) {
338 updateOptions( getOptions() );
340 else if ( o == _show_default_node_shapes_external_cbmi ) {
341 updateOptions( getOptions() );
343 else if ( o == _about_item ) {
346 else if ( o == _help_item ) {
348 AptxUtil.openWebsite( Constants.APTX_DOC_SITE, true, this );
350 catch ( final IOException e1 ) {
351 ForesterUtil.printErrorMessage( Constants.PRG_NAME, e1.toString() );
354 else if ( o == _website_item ) {
356 AptxUtil.openWebsite( Constants.APTX_WEB_SITE, true, this );
358 catch ( final IOException e1 ) {
359 ForesterUtil.printErrorMessage( Constants.PRG_NAME, e1.toString() );
362 else if ( o == _phyloxml_website_item ) {
364 AptxUtil.openWebsite( Constants.PHYLOXML_WEB_SITE, true, this );
366 catch ( final IOException e1 ) {
367 ForesterUtil.printErrorMessage( Constants.PRG_NAME, e1.toString() );
370 else if ( o == _aptx_ref_item ) {
372 AptxUtil.openWebsite( Constants.APTX_REFERENCE_URL, true, this );
374 catch ( final IOException e1 ) {
375 ForesterUtil.printErrorMessage( Constants.PRG_NAME, e1.toString() );
378 else if ( o == _phyloxml_ref_item ) {
380 AptxUtil.openWebsite( Constants.PHYLOXML_REFERENCE_URL, true, this );
382 catch ( final IOException e1 ) {
383 ForesterUtil.printErrorMessage( Constants.PRG_NAME, e1.toString() );
386 else if ( o == _color_by_taxonomic_group_cbmi ) {
387 updateOptions( getOptions() );
389 else if ( o == _line_up_renderable_data_cbmi ) {
390 if ( !_line_up_renderable_data_cbmi.isSelected() ) {
391 _right_line_up_domains_cbmi.setSelected( false );
393 updateOptions( getOptions() );
395 else if ( o == _right_line_up_domains_cbmi ) {
396 if ( _right_line_up_domains_cbmi.isSelected() ) {
397 _line_up_renderable_data_cbmi.setSelected( true );
399 updateOptions( getOptions() );
401 else if ( o == _write_to_pdf_item ) {
402 final File curr_dir = MainFrame.writeToPdf( _mainpanel.getCurrentPhylogeny(),
404 _writetopdf_filechooser,
408 if ( curr_dir != null ) {
409 setCurrentDir( curr_dir );
412 else if ( o == _write_to_jpg_item ) {
413 final File curr_dir = MainFrame.writeToGraphicsFile( _mainpanel.getCurrentPhylogeny(),
414 GraphicsExportType.JPG,
416 _writetographics_filechooser,
420 if ( curr_dir != null ) {
421 setCurrentDir( curr_dir );
424 else if ( o == _write_to_gif_item ) {
425 final File curr_dir = MainFrame.writeToGraphicsFile( _mainpanel.getCurrentPhylogeny(),
426 GraphicsExportType.GIF,
428 _writetographics_filechooser,
432 if ( curr_dir != null ) {
433 setCurrentDir( curr_dir );
436 else if ( o == _write_to_tif_item ) {
437 final File curr_dir = MainFrame.writeToGraphicsFile( _mainpanel.getCurrentPhylogeny(),
438 GraphicsExportType.TIFF,
440 _writetographics_filechooser,
444 if ( curr_dir != null ) {
445 setCurrentDir( curr_dir );
448 else if ( o == _write_to_bmp_item ) {
449 final File curr_dir = MainFrame.writeToGraphicsFile( _mainpanel.getCurrentPhylogeny(),
450 GraphicsExportType.BMP,
452 _writetographics_filechooser,
456 if ( curr_dir != null ) {
457 setCurrentDir( curr_dir );
460 else if ( o == _write_to_png_item ) {
461 final File curr_dir = MainFrame.writeToGraphicsFile( _mainpanel.getCurrentPhylogeny(),
462 GraphicsExportType.PNG,
464 _writetographics_filechooser,
468 if ( curr_dir != null ) {
469 setCurrentDir( curr_dir );
472 else if ( o == _print_item ) {
473 MainFrame.print( getCurrentTreePanel(), getOptions(), this );
475 else if ( o == _save_item ) {
476 final File new_dir = MainFrame.writeToFile( _mainpanel.getCurrentPhylogeny(),
482 if ( new_dir != null ) {
483 setCurrentDir( new_dir );
486 else if ( o == _graphics_export_visible_only_cbmi ) {
487 updateOptions( getOptions() );
489 else if ( o == _antialias_print_cbmi ) {
490 updateOptions( getOptions() );
492 else if ( o == _print_black_and_white_cbmi ) {
493 updateOptions( getOptions() );
495 else if ( o == _print_using_actual_size_cbmi ) {
496 updateOptions( getOptions() );
498 else if ( o == _graphics_export_using_actual_size_cbmi ) {
499 updateOptions( getOptions() );
501 else if ( o == _print_size_mi ) {
504 else if ( o == _choose_pdf_width_mi ) {
511 public void destroy() {
512 AptxUtil.printAppletMessage( NAME, "going to be destroyed " );
513 removeAllTextFrames();
514 if ( getMainPanel() != null ) {
515 getMainPanel().terminate();
520 * This method returns the current external node data which
521 * has been selected by the user by clicking the "Return ..."
522 * menu item. This method is expected to be called from Javascript or
525 * @return current external node data as String
527 public String getCurrentExternalNodesDataBuffer() {
528 return getCurrentTreePanel().getCurrentExternalNodesDataBufferAsString();
531 public int getCurrentExternalNodesDataBufferChangeCounter() {
532 return getCurrentTreePanel().getCurrentExternalNodesDataBufferChangeCounter();
535 public int getCurrentExternalNodesDataBufferLength() {
536 return getCurrentTreePanel().getCurrentExternalNodesDataBufferAsString().length();
540 * This method returns the current phylogeny as a string in the chosen format
542 * @param format must be NH, NHX, NEXUS or PHYLOXML
543 * @return the phylogeny string
544 * @author Herve Menager
546 public String getCurrentPhylogeny( final String format ) {
547 removeAllTextFrames();
548 if ( ( getMainPanel().getCurrentPhylogeny() == null ) || getMainPanel().getCurrentPhylogeny().isEmpty()
549 || ( getMainPanel().getCurrentPhylogeny().getNumberOfExternalNodes() > 10000 ) ) {
552 switch ( ForesterConstants.PhylogeneticTreeFormats.valueOf( format ) ) {
554 return getMainPanel().getCurrentPhylogeny().toNewHampshire();
556 return getMainPanel().getCurrentPhylogeny().toNewHampshireX();
558 return getMainPanel().getCurrentPhylogeny().toNexus();
560 return getMainPanel().getCurrentPhylogeny().toPhyloXML( -1 );
568 * This method returns a view of the current phylogeny in a chosen
569 * graphics format, base64-encoded in a string so that in can be used
572 * @param format must be GraphicsExportType (gif, jpg, pdf, png, tif, bmp)
573 * @return the phylogeny string
574 * @author Herve Menager
576 public String getCurrentPhylogenyGraphicsAsBase64EncodedString( final String format ) {
577 final ByteArrayOutputStream baos = new ByteArrayOutputStream();
579 AptxUtil.writePhylogenyToGraphicsByteArrayOutputStream( baos,
580 _mainpanel.getWidth(),
581 _mainpanel.getHeight(),
582 getCurrentTreePanel(),
583 getCurrentTreePanel().getControlPanel(),
584 GraphicsExportType.valueOf( format ),
587 catch ( final IOException ioe ) {
588 ForesterUtil.printErrorMessage( NAME, ioe.toString() );
589 ioe.printStackTrace();
590 JOptionPane.showMessageDialog( this,
591 NAME + ": Failed to generate graphics: " + "\nException: " + ioe,
592 "Failed to generate graphics",
593 JOptionPane.ERROR_MESSAGE );
596 final byte[] bytes = baos.toByteArray();
597 final String dataImg = Base64.encodeBase64String( bytes );
601 public Options getOptions() {
607 _writetopdf_filechooser = new JFileChooser();
608 _writetopdf_filechooser.setMultiSelectionEnabled( false );
609 _writetopdf_filechooser.addChoosableFileFilter( MainFrame.pdffilter );
610 _writetographics_filechooser = new JFileChooser();
611 _writetographics_filechooser.setMultiSelectionEnabled( false );
612 _writetographics_filechooser.addChoosableFileFilter( MainFrame.graphicsfilefilter );
613 _save_filechooser = new JFileChooser();
614 _save_filechooser.setMultiSelectionEnabled( false );
615 _save_filechooser.setFileFilter( MainFrame.xmlfilter );
616 _save_filechooser.addChoosableFileFilter( MainFrame.nhfilter );
617 _save_filechooser.addChoosableFileFilter( MainFrame.nexusfilter );
618 _save_filechooser.addChoosableFileFilter( _save_filechooser.getAcceptAllFileFilter() );
620 final String home_dir = System.getProperty( "user.home" );
621 _save_filechooser.setCurrentDirectory( new File( home_dir ) );
622 _writetopdf_filechooser.setCurrentDirectory( new File( home_dir ) );
623 _writetographics_filechooser.setCurrentDirectory( new File( home_dir ) );
625 catch ( final Exception e ) {
627 // Do nothing. Not important.
629 final String config_filename = getParameter( Constants.APPLET_PARAM_NAME_FOR_CONFIG_FILE_URL );
630 AptxUtil.printAppletMessage( NAME, "URL for configuration file is: " + config_filename );
631 final Configuration configuration = new Configuration( config_filename, true, true, true );
632 setConfiguration( configuration );
633 setOptions( Options.createInstance( configuration ) );
635 final String tree_url_str = getParameter( Constants.APPLET_PARAM_NAME_FOR_URL_OF_TREE_TO_LOAD );
636 if ( ForesterUtil.isEmpty( tree_url_str ) ) {
637 ForesterUtil.printErrorMessage( NAME, "could not get tree URL from "
638 + Constants.APPLET_PARAM_NAME_FOR_URL_OF_TREE_TO_LOAD );
639 JOptionPane.showMessageDialog( this, NAME + ": could not get tree URL from "
640 + Constants.APPLET_PARAM_NAME_FOR_URL_OF_TREE_TO_LOAD, "Failed get URL", JOptionPane.ERROR_MESSAGE );
643 AptxUtil.printAppletMessage( NAME, "URL for phylogenies is " + tree_url_str );
644 // Get URL to tree file
647 phys_url = new URL( tree_url_str );
649 catch ( final Exception e ) {
650 ForesterUtil.printErrorMessage( NAME, "error: " + e );
652 JOptionPane.showMessageDialog( this, NAME + ": Could not create URL from: \"" + tree_url_str
653 + "\"\nException: " + e, "Failed to create URL", JOptionPane.ERROR_MESSAGE );
655 if ( phys_url == null ) {
656 ForesterUtil.printErrorMessage( NAME, "failed to get tree URL from "
657 + Constants.APPLET_PARAM_NAME_FOR_URL_OF_TREE_TO_LOAD );
658 JOptionPane.showMessageDialog( this,
659 NAME + ": Could not create URL from: \"" + tree_url_str,
660 "Failed to create URL",
661 JOptionPane.ERROR_MESSAGE );
664 // Load the tree from URL
665 Phylogeny[] phys = null;
667 phys = AptxUtil.readPhylogeniesFromUrl( phys_url,
668 getConfiguration().isValidatePhyloXmlAgainstSchema(),
669 getConfiguration().isReplaceUnderscoresInNhParsing(),
670 getConfiguration().isInternalNumberAreConfidenceForNhParsing(),
671 getConfiguration().getTaxonomyExtraction(),
672 getConfiguration().isMidpointReroot() );
674 catch ( final Exception e ) {
675 ForesterUtil.printErrorMessage( NAME, e.toString() );
677 JOptionPane.showMessageDialog( this,
678 NAME + ": Failed to read phylogenies: " + "\nException: " + e,
679 "Failed to read phylogenies",
680 JOptionPane.ERROR_MESSAGE );
682 if ( phys == null ) {
683 ForesterUtil.printErrorMessage( NAME, "phylogenies from [" + phys_url + "] are null" );
684 JOptionPane.showMessageDialog( this,
685 NAME + ": phylogenies from [" + phys_url + "] are null",
686 "Failed to read phylogenies",
687 JOptionPane.ERROR_MESSAGE );
690 else if ( phys.length < 1 ) {
691 ForesterUtil.printErrorMessage( NAME, "phylogenies from [" + phys_url + "] are empty" );
692 JOptionPane.showMessageDialog( this,
693 NAME + ": phylogenies from [" + phys_url + "] are empty",
694 "Failed to read phylogenies",
695 JOptionPane.ERROR_MESSAGE );
699 AptxUtil.printAppletMessage( NAME, "loaded " + phys.length + " phylogenies from: " + phys_url );
702 final String species_tree_url_str = getParameter( Constants.APPLET_PARAM_NAME_FOR_URL_OF_SPECIES_TREE_TO_LOAD );
703 if ( !ForesterUtil.isEmpty( species_tree_url_str ) ) {
704 AptxUtil.printAppletMessage( NAME, "URL of species tree to load: \"" + species_tree_url_str + "\"" );
705 Phylogeny[] species_trees = null;
707 final URL species_tree_url = new URL( species_tree_url_str );
708 species_trees = AptxUtil.readPhylogeniesFromUrl( species_tree_url,
709 configuration.isValidatePhyloXmlAgainstSchema(),
710 configuration.isReplaceUnderscoresInNhParsing(),
712 TAXONOMY_EXTRACTION.NO,
715 catch ( final IOException e ) {
716 ForesterUtil.printErrorMessage( NAME, "could not read species tree from [" + species_tree_url_str
718 JOptionPane.showMessageDialog( this, NAME + ": could not read species tree from ["
719 + species_tree_url_str + "]", "Failed to read species tree", JOptionPane.ERROR_MESSAGE );
721 if ( ( species_trees != null ) && ( species_trees.length > 0 ) ) {
722 AptxUtil.printAppletMessage( NAME, "successfully read species tree" );
723 if ( species_trees[ 0 ].isEmpty() ) {
724 ForesterUtil.printErrorMessage( NAME, "species tree is empty" );
726 else if ( !species_trees[ 0 ].isRooted() ) {
727 ForesterUtil.printErrorMessage( NAME, "species tree is not rooted" );
730 setSpeciesTree( species_trees[ 0 ] );
731 AptxUtil.printAppletMessage( NAME, "species tree OK" );
738 setMainPanel( new MainPanelApplets( getConfiguration(), this ) );
739 _jmenubar = new JMenuBar();
740 if ( !getConfiguration().isHideControlPanelAndMenubar() ) {
742 if ( !getConfiguration().isUseNativeUI() ) {
743 _jmenubar.setBackground( getConfiguration().getGuiMenuBackgroundColor() );
745 if ( getSpeciesTree() != null ) {
754 setJMenuBar( _jmenubar );
756 final Container contentpane = getContentPane();
757 contentpane.setLayout( new BorderLayout() );
758 contentpane.add( getMainPanel(), BorderLayout.CENTER );
759 addComponentListener( new ComponentAdapter() {
762 public void componentResized( final ComponentEvent e ) {
763 if ( getMainPanel().getCurrentTreePanel() != null ) {
764 getMainPanel().getCurrentTreePanel().calcParametersForPainting( getMainPanel()
765 .getCurrentTreePanel()
768 .getCurrentTreePanel()
773 if ( getConfiguration().isUseTabbedDisplay() ) {
775 AptxUtil.printAppletMessage( NAME, "using tabbed display" );
776 AptxUtil.addPhylogeniesToTabs( phys,
777 new File( phys_url.getFile() ).getName(),
782 catch ( final Exception e ) {
783 ForesterUtil.printErrorMessage( NAME, e.toString() );
788 AptxUtil.printAppletMessage( NAME, "not using tabbed display" );
789 if ( getSpeciesTree() != null ) {
790 AptxUtil.printAppletMessage( NAME,
791 "Warning: gsdi (gene duplication inference) only available tabbed display" );
793 AptxUtil.addPhylogenyToPanel( phys, getConfiguration(), getMainPanel() );
797 getMainPanel().getControlPanel().showWholeAll();
798 getMainPanel().getControlPanel().showWhole();
800 getCurrentTreePanel().getControlPanel().getSequenceRelationTypeBox().removeAllItems();
801 for( final SequenceRelation.SEQUENCE_RELATION_TYPE type : getMainPanel().getCurrentPhylogeny()
802 .getRelevantSequenceRelationTypes() ) {
803 getCurrentTreePanel().getControlPanel().getSequenceRelationTypeBox().addItem( type );
805 final String default_relation = getParameter( Constants.APPLET_PARAM_NAME_FOR_DEFAULT_SEQUENCE_RELATION_TYPE );
806 if ( default_relation != null ) {
807 getCurrentTreePanel().getControlPanel().getSequenceRelationTypeBox().setSelectedItem( default_relation );
809 final String default_sequence = getParameter( Constants.APPLET_PARAM_NAME_FOR_DEFAULT_QUERY_SEQUENCE );
810 if ( default_sequence != null ) {
811 getCurrentTreePanel().getControlPanel().getSequenceRelationBox().setSelectedItem( default_sequence );
815 AptxUtil.printAppletMessage( NAME, "successfully initialized" );
818 catch ( final Exception e ) {
819 ForesterUtil.printErrorMessage( NAME, e.toString() );
824 public void showTextFrame( final String s, final String title ) {
826 _textframes.addLast( TextFrame.instantiate( s, title, _textframes ) );
830 public void start() {
831 if ( getMainPanel() != null ) {
832 getMainPanel().validate();
835 requestFocusInWindow();
837 AptxUtil.printAppletMessage( NAME, "started" );
840 private void chooseFont() {
841 final FontChooser fc = new FontChooser();
842 fc.setFont( getMainPanel().getTreeFontSet().getLargeFont() );
843 fc.showDialog( this, "Select the Base Font" );
844 getMainPanel().getTreeFontSet().setBaseFont( fc.getFont() );
847 private void chooseMinimalConfidence() {
848 final String s = ( String ) JOptionPane
849 .showInputDialog( this,
850 "Please the minimum for confidence values to be displayed.\n" + "[current value: "
851 + getOptions().getMinConfidenceValue() + "]\n",
852 "Minimal Confidence Value",
853 JOptionPane.QUESTION_MESSAGE,
856 getOptions().getMinConfidenceValue() );
857 if ( !ForesterUtil.isEmpty( s ) ) {
858 boolean success = true;
860 final String m_str = s.trim();
861 if ( !ForesterUtil.isEmpty( m_str ) ) {
863 m = Double.parseDouble( m_str );
865 catch ( final Exception ex ) {
872 if ( success && ( m >= 0.0 ) ) {
873 getOptions().setMinConfidenceValue( m );
878 private void choosePdfWidth() {
879 final String s = ( String ) JOptionPane.showInputDialog( this,
880 "Please enter the default line width for PDF export.\n"
882 + getOptions().getPrintLineWidth() + "]\n",
883 "Line Width for PDF Export",
884 JOptionPane.QUESTION_MESSAGE,
887 getOptions().getPrintLineWidth() );
888 if ( !ForesterUtil.isEmpty( s ) ) {
889 boolean success = true;
891 final String m_str = s.trim();
892 if ( !ForesterUtil.isEmpty( m_str ) ) {
894 f = Float.parseFloat( m_str );
896 catch ( final Exception ex ) {
903 if ( success && ( f > 0.0 ) ) {
904 getOptions().setPrintLineWidth( f );
909 private void choosePrintSize() {
910 final String s = ( String ) JOptionPane.showInputDialog( this,
911 "Please enter values for width and height,\nseparated by a comma.\n"
912 + "[current values: "
913 + getOptions().getPrintSizeX() + ", "
914 + getOptions().getPrintSizeY() + "]\n"
915 + "[A4: " + Constants.A4_SIZE_X + ", "
916 + Constants.A4_SIZE_Y + "]\n" + "[US Letter: "
917 + Constants.US_LETTER_SIZE_X + ", "
918 + Constants.US_LETTER_SIZE_Y + "]",
919 "Default Size for Graphics Export",
920 JOptionPane.QUESTION_MESSAGE,
923 getOptions().getPrintSizeX() + ", "
924 + getOptions().getPrintSizeY() );
925 if ( !ForesterUtil.isEmpty( s ) && ( s.indexOf( ',' ) > 0 ) ) {
926 boolean success = true;
929 final String[] str_ary = s.split( "," );
930 if ( str_ary.length == 2 ) {
931 final String x_str = str_ary[ 0 ].trim();
932 final String y_str = str_ary[ 1 ].trim();
933 if ( !ForesterUtil.isEmpty( x_str ) && !ForesterUtil.isEmpty( y_str ) ) {
935 x = Integer.parseInt( x_str );
936 y = Integer.parseInt( y_str );
938 catch ( final Exception ex ) {
949 if ( success && ( x > 1 ) && ( y > 1 ) ) {
950 getOptions().setPrintSizeX( x );
951 getOptions().setPrintSizeY( y );
956 private void customizeRadioButtonMenuItem( final JRadioButtonMenuItem item, final boolean is_selected ) {
957 if ( item != null ) {
958 item.setFont( MainFrame.menu_font );
959 if ( !getConfiguration().isUseNativeUI() ) {
960 item.setBackground( getConfiguration().getGuiMenuBackgroundColor() );
961 item.setForeground( getConfiguration().getGuiMenuTextColor() );
963 item.setSelected( is_selected );
964 item.addActionListener( this );
968 private Phylogeny getSpeciesTree() {
969 return _species_tree;
972 private boolean isScreenAntialias() {
976 private void removeBranchColors() {
977 if ( getMainPanel().getCurrentPhylogeny() != null ) {
978 AptxUtil.removeBranchColors( getMainPanel().getCurrentPhylogeny() );
982 private void removeVisualStyles() {
983 if ( getMainPanel().getCurrentPhylogeny() != null ) {
984 AptxUtil.removeVisualStyles( getMainPanel().getCurrentPhylogeny() );
988 private void setMainPanel( final MainPanelApplets main_panel ) {
989 _mainpanel = main_panel;
992 private void setSpeciesTree( final Phylogeny species_tree ) {
993 _species_tree = species_tree;
996 private void setupUI() {
998 if ( getConfiguration().isUseNativeUI() ) {
999 UIManager.setLookAndFeel( UIManager.getSystemLookAndFeelClassName() );
1002 UIManager.setLookAndFeel( UIManager.getCrossPlatformLookAndFeelClassName() );
1005 catch ( final UnsupportedLookAndFeelException e ) {
1006 AptxUtil.dieWithSystemError( "UnsupportedLookAndFeelException: " + e.toString() );
1008 catch ( final ClassNotFoundException e ) {
1009 AptxUtil.dieWithSystemError( "ClassNotFoundException: " + e.toString() );
1011 catch ( final InstantiationException e ) {
1012 AptxUtil.dieWithSystemError( "InstantiationException: " + e.toString() );
1014 catch ( final IllegalAccessException e ) {
1015 AptxUtil.dieWithSystemError( "IllegalAccessException: " + e.toString() );
1017 catch ( final Exception e ) {
1018 AptxUtil.dieWithSystemError( e.toString() );
1022 void buildAnalysisMenu() {
1023 _analysis_menu = MainFrame.createMenu( "Analysis", getConfiguration() );
1024 _analysis_menu.add( _gsdi_item = new JMenuItem( "GSDI (Generalized Speciation Duplication Inference)" ) );
1025 _analysis_menu.add( _gsdir_item = new JMenuItem( "GSDIR (GSDI with re-rooting)" ) );
1026 customizeJMenuItem( _gsdi_item );
1027 customizeJMenuItem( _gsdir_item );
1028 // _analysis_menu.addSeparator();
1029 // _analysis_menu.add( _lineage_inference = new JMenuItem( INFER_ANCESTOR_TAXONOMIES ) );
1030 // customizeJMenuItem( _lineage_inference );
1031 // _lineage_inference.setToolTipText( "Inference of ancestor taxonomies/lineages" );
1032 _jmenubar.add( _analysis_menu );
1035 void buildFileMenu() {
1036 _file_jmenu = MainFrame.createMenu( "File", getConfiguration() );
1037 _file_jmenu.add( _save_item = new JMenuItem( "Save Tree As..." ) );
1038 _file_jmenu.addSeparator();
1039 _file_jmenu.add( _write_to_pdf_item = new JMenuItem( "Export to PDF file ..." ) );
1040 if ( AptxUtil.canWriteFormat( "tif" ) || AptxUtil.canWriteFormat( "tiff" ) || AptxUtil.canWriteFormat( "TIF" ) ) {
1041 _file_jmenu.add( _write_to_tif_item = new JMenuItem( "Export to TIFF file..." ) );
1043 _file_jmenu.add( _write_to_png_item = new JMenuItem( "Export to PNG file..." ) );
1044 _file_jmenu.add( _write_to_jpg_item = new JMenuItem( "Export to JPG file..." ) );
1045 if ( AptxUtil.canWriteFormat( "gif" ) ) {
1046 _file_jmenu.add( _write_to_gif_item = new JMenuItem( "Export to GIF file..." ) );
1048 if ( AptxUtil.canWriteFormat( "bmp" ) ) {
1049 _file_jmenu.add( _write_to_bmp_item = new JMenuItem( "Export to BMP file..." ) );
1051 _file_jmenu.addSeparator();
1052 _file_jmenu.add( _print_item = new JMenuItem( "Print..." ) );
1053 customizeJMenuItem( _save_item );
1054 customizeJMenuItem( _write_to_pdf_item );
1055 customizeJMenuItem( _write_to_png_item );
1056 customizeJMenuItem( _write_to_jpg_item );
1057 customizeJMenuItem( _write_to_gif_item );
1058 customizeJMenuItem( _write_to_tif_item );
1059 customizeJMenuItem( _write_to_bmp_item );
1060 customizeJMenuItem( _print_item );
1061 _jmenubar.add( _file_jmenu );
1064 void buildFontSizeMenu() {
1065 _font_size_menu = MainFrame.createMenu( MainFrame.FONT_SIZE_MENU_LABEL, getConfiguration() );
1066 _font_size_menu.add( _super_tiny_fonts_mi = new JMenuItem( "Super tiny fonts" ) );
1067 _font_size_menu.add( _tiny_fonts_mi = new JMenuItem( "Tiny fonts" ) );
1068 _font_size_menu.add( _small_fonts_mi = new JMenuItem( "Small fonts" ) );
1069 _font_size_menu.add( _medium_fonts_mi = new JMenuItem( "Medium fonts" ) );
1070 _font_size_menu.add( _large_fonts_mi = new JMenuItem( "Large fonts" ) );
1071 customizeJMenuItem( _super_tiny_fonts_mi );
1072 customizeJMenuItem( _tiny_fonts_mi );
1073 customizeJMenuItem( _small_fonts_mi );
1074 customizeJMenuItem( _medium_fonts_mi );
1075 customizeJMenuItem( _large_fonts_mi );
1076 _jmenubar.add( _font_size_menu );
1079 void buildHelpMenu() {
1080 _help_jmenu = MainFrame.createMenu( "Help", getConfiguration() );
1081 _help_jmenu.add( _help_item = new JMenuItem( "Documentation" ) );
1082 _help_jmenu.addSeparator();
1083 _help_jmenu.add( _website_item = new JMenuItem( "Archaeopteryx Home" ) );
1084 _aptx_ref_item = new JMenuItem( "Archaeopteryx Reference" );
1085 _help_jmenu.add( _phyloxml_website_item = new JMenuItem( "phyloXML Home" ) );
1086 _help_jmenu.add( _phyloxml_ref_item = new JMenuItem( "phyloXML Reference" ) );
1087 _help_jmenu.addSeparator();
1088 _help_jmenu.add( _about_item = new JMenuItem( "About" ) );
1089 customizeJMenuItem( _help_item );
1090 customizeJMenuItem( _website_item );
1091 customizeJMenuItem( _phyloxml_website_item );
1092 customizeJMenuItem( _aptx_ref_item );
1093 customizeJMenuItem( _phyloxml_ref_item );
1094 customizeJMenuItem( _about_item );
1095 _phyloxml_ref_item.setToolTipText( MainFrame.PHYLOXML_REF_TOOL_TIP );
1096 _aptx_ref_item.setToolTipText( MainFrame.APTX_REF_TOOL_TIP );
1097 _jmenubar.add( _help_jmenu );
1100 void buildOptionsMenu() {
1101 _options_jmenu = MainFrame.createMenu( MainFrame.OPTIONS_HEADER, getConfiguration() );
1102 _options_jmenu.addChangeListener( new ChangeListener() {
1105 public void stateChanged( final ChangeEvent e ) {
1106 MainFrame.setOvPlacementColorChooseMenuItem( _overview_placment_mi, getOptions() );
1107 MainFrame.setTextColorChooseMenuItem( _switch_colors_mi, getCurrentTreePanel() );
1109 .setTextMinSupportMenuItem( _choose_minimal_confidence_mi, getOptions(), getCurrentTreePanel() );
1110 MainFrame.setTextForFontChooserMenuItem( _choose_font_mi, MainFrame
1111 .createCurrentFontDesc( getMainPanel().getTreeFontSet() ) );
1112 setTextForGraphicsSizeChooserMenuItem( _print_size_mi, getOptions() );
1113 setTextForPdfLineWidthChooserMenuItem( _choose_pdf_width_mi, getOptions() );
1114 MainFrame.setCycleNodeFillMenuItem( _cycle_node_fill_mi, getOptions() );
1115 MainFrame.setCycleNodeShapeMenuItem( _cycle_node_shape_mi, getOptions() );
1116 MainFrame.setTextNodeSizeMenuItem( _choose_node_size_mi, getOptions() );
1118 getMainPanel().getControlPanel().setVisibilityOfDomainStrucureCB();
1119 getMainPanel().getControlPanel().setVisibilityOfX();
1121 catch ( final Exception ignore ) {
1122 // do nothing, not important.
1126 _options_jmenu.add( MainFrame.customizeMenuItemAsLabel( new JMenuItem( MainFrame.DISPLAY_SUBHEADER ),
1127 getConfiguration() ) );
1129 .add( _ext_node_dependent_cladogram_rbmi = new JRadioButtonMenuItem( MainFrame.NONUNIFORM_CLADOGRAMS_LABEL ) );
1130 _options_jmenu.add( _uniform_cladograms_rbmi = new JRadioButtonMenuItem( MainFrame.UNIFORM_CLADOGRAMS_LABEL ) );
1132 .add( _non_lined_up_cladograms_rbmi = new JRadioButtonMenuItem( MainFrame.NON_LINED_UP_CLADOGRAMS_LABEL ) );
1133 _radio_group_1 = new ButtonGroup();
1134 _radio_group_1.add( _ext_node_dependent_cladogram_rbmi );
1135 _radio_group_1.add( _uniform_cladograms_rbmi );
1136 _radio_group_1.add( _non_lined_up_cladograms_rbmi );
1137 _options_jmenu.add( _show_overview_cbmi = new JCheckBoxMenuItem( MainFrame.SHOW_OVERVIEW_LABEL ) );
1138 _options_jmenu.add( _show_scale_cbmi = new JCheckBoxMenuItem( MainFrame.DISPLAY_SCALE_LABEL ) );
1140 .add( _show_default_node_shapes_internal_cbmi = new JCheckBoxMenuItem( MainFrame.DISPLAY_NODE_BOXES_LABEL_INT ) );
1142 .add( _show_default_node_shapes_external_cbmi = new JCheckBoxMenuItem( MainFrame.DISPLAY_NODE_BOXES_LABEL_EXT ) );
1144 .add( _show_default_node_shapes_for_marked_cbmi = new JCheckBoxMenuItem( MainFrame.DISPLAY_NODE_BOXES_LABEL_MARKED ) );
1145 _options_jmenu.add( _line_up_renderable_data_cbmi = new JCheckBoxMenuItem( MainFrame.LINE_UP_RENDERABLE_DATA ) );
1146 if ( getConfiguration().doDisplayOption( Configuration.show_domain_architectures ) ) {
1147 _options_jmenu.add( _right_line_up_domains_cbmi = new JCheckBoxMenuItem( MainFrame.RIGHT_LINE_UP_DOMAINS ) );
1148 _options_jmenu.add( _show_domain_labels = new JCheckBoxMenuItem( MainFrame.SHOW_DOMAIN_LABELS_LABEL ) );
1150 _options_jmenu.add( _show_annotation_ref_source = new JCheckBoxMenuItem( MainFrame.SHOW_ANN_REF_SOURCE_LABEL ) );
1151 _options_jmenu.add( _show_confidence_stddev_cbmi = new JCheckBoxMenuItem( MainFrame.SHOW_CONF_STDDEV_LABEL ) );
1153 .add( _color_by_taxonomic_group_cbmi = new JCheckBoxMenuItem( MainFrame.COLOR_BY_TAXONOMIC_GROUP ) );
1155 .add( _color_labels_same_as_parent_branch = new JCheckBoxMenuItem( MainFrame.COLOR_LABELS_LABEL ) );
1156 _color_labels_same_as_parent_branch.setToolTipText( MainFrame.COLOR_LABELS_TIP );
1157 _options_jmenu.add( _abbreviate_scientific_names = new JCheckBoxMenuItem( MainFrame.ABBREV_SN_LABEL ) );
1158 _options_jmenu.add( _label_direction_cbmi = new JCheckBoxMenuItem( MainFrame.LABEL_DIRECTION_LABEL ) );
1159 _label_direction_cbmi.setToolTipText( MainFrame.LABEL_DIRECTION_TIP );
1160 _options_jmenu.add( _screen_antialias_cbmi = new JCheckBoxMenuItem( MainFrame.SCREEN_ANTIALIAS_LABEL ) );
1161 _options_jmenu.add( _background_gradient_cbmi = new JCheckBoxMenuItem( MainFrame.BG_GRAD_LABEL ) );
1162 _options_jmenu.add( _cycle_node_shape_mi = new JMenuItem( MainFrame.CYCLE_NODE_SHAPE_LABEL ) );
1163 _options_jmenu.add( _cycle_node_fill_mi = new JMenuItem( MainFrame.CYCLE_NODE_FILL_LABEL ) );
1164 _options_jmenu.add( _choose_node_size_mi = new JMenuItem( MainFrame.CHOOSE_NODE_SIZE_LABEL ) );
1165 _options_jmenu.add( _choose_minimal_confidence_mi = new JMenuItem( "" ) );
1166 _options_jmenu.add( _overview_placment_mi = new JMenuItem( "" ) );
1167 _options_jmenu.add( _switch_colors_mi = new JMenuItem( "" ) );
1168 _options_jmenu.add( _choose_font_mi = new JMenuItem( "" ) );
1169 _options_jmenu.addSeparator();
1170 _options_jmenu.add( MainFrame.customizeMenuItemAsLabel( new JMenuItem( MainFrame.SEARCH_SUBHEADER ),
1171 getConfiguration() ) );
1173 .add( _search_case_senstive_cbmi = new JCheckBoxMenuItem( MainFrame.SEARCH_CASE_SENSITIVE_LABEL ) );
1174 _options_jmenu.add( _search_whole_words_only_cbmi = new JCheckBoxMenuItem( MainFrame.SEARCH_TERMS_ONLY_LABEL ) );
1175 _options_jmenu.add( _search_with_regex_cbmi = new JCheckBoxMenuItem( MainFrame.SEARCH_REGEX_LABEL ) );
1176 _search_with_regex_cbmi.setToolTipText( MainFrame.SEARCH_WITH_REGEX_TIP );
1178 .add( _inverse_search_result_cbmi = new JCheckBoxMenuItem( MainFrame.INVERSE_SEARCH_RESULT_LABEL ) );
1180 _options_jmenu.addSeparator();
1181 _options_jmenu.add( MainFrame.customizeMenuItemAsLabel( new JMenuItem( "Graphics Export & Printing:" ),
1182 getConfiguration() ) );
1183 _options_jmenu.add( _antialias_print_cbmi = new JCheckBoxMenuItem( "Antialias" ) );
1184 _options_jmenu.add( _print_black_and_white_cbmi = new JCheckBoxMenuItem( "Export in Black and White" ) );
1186 .add( _print_using_actual_size_cbmi = new JCheckBoxMenuItem( "Use Current Image Size for PDF export and Printing" ) );
1188 .add( _graphics_export_using_actual_size_cbmi = new JCheckBoxMenuItem( "Use Current Image Size for PNG, JPG, and GIF export" ) );
1190 .add( _graphics_export_visible_only_cbmi = new JCheckBoxMenuItem( "Limit to Visible ('Screenshot') for PNG, JPG, and GIF export" ) );
1191 _options_jmenu.add( _print_size_mi = new JMenuItem( "" ) );
1192 _options_jmenu.add( _choose_pdf_width_mi = new JMenuItem( "" ) );
1194 customizeCheckBoxMenuItem( _antialias_print_cbmi, getOptions().isAntialiasPrint() );
1195 customizeCheckBoxMenuItem( _print_black_and_white_cbmi, getOptions().isPrintBlackAndWhite() );
1196 customizeCheckBoxMenuItem( _graphics_export_visible_only_cbmi, getOptions().isGraphicsExportVisibleOnly() );
1197 customizeCheckBoxMenuItem( _print_using_actual_size_cbmi, getOptions().isPrintUsingActualSize() );
1198 customizeCheckBoxMenuItem( _graphics_export_using_actual_size_cbmi, getOptions()
1199 .isGraphicsExportUsingActualSize() );
1200 customizeJMenuItem( _print_size_mi );
1201 customizeJMenuItem( _choose_pdf_width_mi );
1203 customizeJMenuItem( _choose_font_mi );
1204 customizeJMenuItem( _choose_minimal_confidence_mi );
1205 customizeJMenuItem( _switch_colors_mi );
1206 customizeJMenuItem( _overview_placment_mi );
1207 customizeCheckBoxMenuItem( _color_by_taxonomic_group_cbmi, getOptions().isColorByTaxonomicGroup() );
1208 customizeCheckBoxMenuItem( _label_direction_cbmi,
1209 getOptions().getNodeLabelDirection() == NODE_LABEL_DIRECTION.RADIAL );
1210 customizeCheckBoxMenuItem( _screen_antialias_cbmi, getOptions().isAntialiasScreen() );
1211 customizeCheckBoxMenuItem( _background_gradient_cbmi, getOptions().isBackgroundColorGradient() );
1212 customizeCheckBoxMenuItem( _show_domain_labels, getOptions().isShowDomainLabels() );
1213 customizeCheckBoxMenuItem( _show_annotation_ref_source, getOptions().isShowAnnotationRefSource() );
1214 customizeCheckBoxMenuItem( _abbreviate_scientific_names, getOptions().isAbbreviateScientificTaxonNames() );
1215 customizeCheckBoxMenuItem( _show_default_node_shapes_external_cbmi, getOptions()
1216 .isShowDefaultNodeShapesExternal() );
1217 customizeCheckBoxMenuItem( _show_default_node_shapes_internal_cbmi, getOptions()
1218 .isShowDefaultNodeShapesInternal() );
1219 customizeCheckBoxMenuItem( _show_default_node_shapes_for_marked_cbmi, getOptions()
1220 .isShowDefaultNodeShapesForMarkedNodes() );
1221 customizeJMenuItem( _cycle_node_shape_mi );
1222 customizeJMenuItem( _cycle_node_fill_mi );
1223 customizeJMenuItem( _choose_node_size_mi );
1224 customizeCheckBoxMenuItem( _color_labels_same_as_parent_branch, getOptions().isColorLabelsSameAsParentBranch() );
1225 customizeCheckBoxMenuItem( _search_case_senstive_cbmi, getOptions().isSearchCaseSensitive() );
1226 customizeCheckBoxMenuItem( _show_scale_cbmi, getOptions().isShowScale() );
1227 customizeRadioButtonMenuItem( _non_lined_up_cladograms_rbmi,
1228 getOptions().getCladogramType() == CLADOGRAM_TYPE.NON_LINED_UP );
1229 customizeRadioButtonMenuItem( _uniform_cladograms_rbmi,
1230 getOptions().getCladogramType() == CLADOGRAM_TYPE.TOTAL_NODE_SUM_DEP );
1231 customizeRadioButtonMenuItem( _ext_node_dependent_cladogram_rbmi,
1232 getOptions().getCladogramType() == CLADOGRAM_TYPE.EXT_NODE_SUM_DEP );
1233 customizeCheckBoxMenuItem( _show_overview_cbmi, getOptions().isShowOverview() );
1234 customizeCheckBoxMenuItem( _search_with_regex_cbmi, getOptions().isSearchWithRegex() );
1235 customizeCheckBoxMenuItem( _search_whole_words_only_cbmi, getOptions().isMatchWholeTermsOnly() );
1236 customizeCheckBoxMenuItem( _inverse_search_result_cbmi, getOptions().isInverseSearchResult() );
1237 customizeCheckBoxMenuItem( _show_confidence_stddev_cbmi, getOptions().isShowConfidenceStddev() );
1238 customizeCheckBoxMenuItem( _line_up_renderable_data_cbmi, getOptions().isLineUpRendarableNodeData() );
1239 customizeCheckBoxMenuItem( _right_line_up_domains_cbmi, getOptions().isRightLineUpDomains() );
1240 _jmenubar.add( _options_jmenu );
1243 void buildToolsMenu() {
1244 _tools_menu = MainFrame.createMenu( "Tools", getConfiguration() );
1245 _tools_menu.add( _confcolor_item = new JMenuItem( "Colorize Branches Depending on Confidence" ) );
1246 customizeJMenuItem( _confcolor_item );
1247 _tools_menu.add( _taxcolor_item = new JMenuItem( "Taxonomy Colorize Branches" ) );
1248 customizeJMenuItem( _taxcolor_item );
1249 _tools_menu.addSeparator();
1250 _tools_menu.add( _remove_visual_styles_item = new JMenuItem( "Delete All Visual Styles From Nodes" ) );
1251 _remove_visual_styles_item
1252 .setToolTipText( "To remove all node visual styles (fonts, colors) from the current phylogeny." );
1253 customizeJMenuItem( _remove_visual_styles_item );
1254 _tools_menu.add( _remove_branch_color_item = new JMenuItem( "Delete All Colors From Branches" ) );
1255 _remove_branch_color_item.setToolTipText( "To remove all branch color values from the current phylogeny." );
1256 customizeJMenuItem( _remove_branch_color_item );
1257 _tools_menu.addSeparator();
1258 _tools_menu.add( _midpoint_root_item = new JMenuItem( "Midpoint-Root" ) );
1259 customizeJMenuItem( _midpoint_root_item );
1260 _tools_menu.addSeparator();
1261 _tools_menu.add( _collapse_species_specific_subtrees = new JMenuItem( "Collapse Species-Specific Subtrees" ) );
1262 customizeJMenuItem( _collapse_species_specific_subtrees );
1263 _jmenubar.add( _tools_menu );
1266 void buildTypeMenu() {
1267 _type_menu = MainFrame.createMenu( MainFrame.TYPE_MENU_HEADER, getConfiguration() );
1268 _type_menu.add( _rectangular_type_cbmi = new JCheckBoxMenuItem( MainFrame.RECTANGULAR_TYPE_CBMI_LABEL ) );
1269 _type_menu.add( _euro_type_cbmi = new JCheckBoxMenuItem( MainFrame.EURO_TYPE_CBMI_LABEL ) );
1270 _type_menu.add( _rounded_type_cbmi = new JCheckBoxMenuItem( MainFrame.ROUNDED_TYPE_CBMI_LABEL ) );
1271 _type_menu.add( _curved_type_cbmi = new JCheckBoxMenuItem( MainFrame.CURVED_TYPE_CBMI_LABEL ) );
1272 _type_menu.add( _triangular_type_cbmi = new JCheckBoxMenuItem( MainFrame.TRIANGULAR_TYPE_CBMI_LABEL ) );
1273 _type_menu.add( _convex_type_cbmi = new JCheckBoxMenuItem( MainFrame.CONVEX_TYPE_CBMI_LABEL ) );
1274 _type_menu.add( _unrooted_type_cbmi = new JCheckBoxMenuItem( MainFrame.UNROOTED_TYPE_CBMI_LABEL ) );
1275 _type_menu.add( _circular_type_cbmi = new JCheckBoxMenuItem( MainFrame.CIRCULAR_TYPE_CBMI_LABEL ) );
1276 customizeCheckBoxMenuItem( _rectangular_type_cbmi, false );
1277 customizeCheckBoxMenuItem( _triangular_type_cbmi, false );
1278 customizeCheckBoxMenuItem( _euro_type_cbmi, false );
1279 customizeCheckBoxMenuItem( _rounded_type_cbmi, false );
1280 customizeCheckBoxMenuItem( _curved_type_cbmi, false );
1281 customizeCheckBoxMenuItem( _convex_type_cbmi, false );
1282 customizeCheckBoxMenuItem( _unrooted_type_cbmi, false );
1283 customizeCheckBoxMenuItem( _circular_type_cbmi, false );
1284 _unrooted_type_cbmi.setToolTipText( MainFrame.USE_MOUSEWHEEL_SHIFT_TO_ROTATE );
1285 _circular_type_cbmi.setToolTipText( MainFrame.USE_MOUSEWHEEL_SHIFT_TO_ROTATE );
1286 initializeTypeMenu( getOptions() );
1287 _jmenubar.add( _type_menu );
1290 void buildViewMenu() {
1291 _view_jmenu = MainFrame.createMenu( "View", getConfiguration() );
1293 .add( _display_basic_information_item = new JMenuItem( MainFrame.SHOW_BASIC_TREE_INFORMATION_LABEL ) );
1294 _view_jmenu.addSeparator();
1295 _view_jmenu.add( _view_as_XML_item = new JMenuItem( "as phyloXML" ) );
1296 _view_jmenu.add( _view_as_NH_item = new JMenuItem( "as Newick" ) );
1297 _view_jmenu.add( _view_as_nexus_item = new JMenuItem( "as Nexus" ) );
1298 customizeJMenuItem( _display_basic_information_item );
1299 customizeJMenuItem( _view_as_NH_item );
1300 customizeJMenuItem( _view_as_XML_item );
1301 customizeJMenuItem( _view_as_nexus_item );
1302 _jmenubar.add( _view_jmenu );
1305 void checkTextFrames() {
1306 if ( _textframes.size() > 5 ) {
1308 if ( _textframes.getFirst() != null ) {
1309 _textframes.getFirst().removeMe();
1312 _textframes.removeFirst();
1315 catch ( final NoSuchElementException e ) {
1321 void clearCurrentExternalNodesDataBuffer() {
1322 getCurrentTreePanel().clearCurrentExternalNodesDataBuffer();
1325 void customizeCheckBoxMenuItem( final JCheckBoxMenuItem item, final boolean is_selected ) {
1326 if ( item != null ) {
1327 item.setFont( MainFrame.menu_font );
1328 if ( !getConfiguration().isUseNativeUI() ) {
1329 item.setBackground( getConfiguration().getGuiMenuBackgroundColor() );
1330 item.setForeground( getConfiguration().getGuiMenuTextColor() );
1332 item.setSelected( is_selected );
1333 item.addActionListener( this );
1337 void customizeJMenuItem( final JMenuItem jmi ) {
1338 if ( jmi != null ) {
1339 jmi.setFont( MainFrame.menu_font );
1340 if ( !getConfiguration().isUseNativeUI() ) {
1341 jmi.setBackground( getConfiguration().getGuiMenuBackgroundColor() );
1342 jmi.setForeground( getConfiguration().getGuiMenuTextColor() );
1344 jmi.addActionListener( this );
1348 void displayBasicInformation() {
1349 if ( ( getMainPanel() != null ) && ( getMainPanel().getCurrentPhylogeny() != null )
1350 && !getMainPanel().getCurrentPhylogeny().isEmpty() ) {
1351 String title = "Basic Information";
1352 if ( !ForesterUtil.isEmpty( getMainPanel().getCurrentPhylogeny().getName() ) ) {
1353 title = title + " for \"" + _mainpanel.getCurrentPhylogeny().getName() + "\"";
1355 showTextFrame( AptxUtil.createBasicInformation( getMainPanel().getCurrentPhylogeny(), null ), title );
1359 void executeGSDI() {
1360 if ( !isOKforSDI( false, true ) ) {
1363 if ( !_mainpanel.getCurrentPhylogeny().isRooted() ) {
1364 JOptionPane.showMessageDialog( this,
1365 "Gene tree is not rooted.",
1366 "Cannot execute GSDI",
1367 JOptionPane.ERROR_MESSAGE );
1370 final Phylogeny gene_tree = _mainpanel.getCurrentPhylogeny().copy();
1371 gene_tree.setAllNodesToNotCollapse();
1372 gene_tree.recalculateNumberOfExternalDescendants( false );
1374 final Phylogeny species_tree = _species_tree.copy();
1376 gsdi = new GSDI( gene_tree, species_tree, false, true, true, true );
1378 catch ( final SDIException e ) {
1379 JOptionPane.showMessageDialog( this,
1380 e.getLocalizedMessage(),
1381 "Error during GSDI",
1382 JOptionPane.ERROR_MESSAGE );
1385 catch ( final Exception e ) {
1386 AptxUtil.unexpectedException( e );
1389 gene_tree.setRerootable( false );
1390 gene_tree.clearHashIdToNodeMap();
1391 gene_tree.recalculateNumberOfExternalDescendants( true );
1392 _mainpanel.addPhylogenyInNewTab( gene_tree, getConfiguration(), "gene tree", null );
1393 getMainPanel().getControlPanel().setShowEvents( true );
1395 final int selected = _mainpanel.getTabbedPane().getSelectedIndex();
1396 _mainpanel.addPhylogenyInNewTab( species_tree, getConfiguration(), "species tree", null );
1398 _mainpanel.getTabbedPane().setSelectedIndex( selected );
1400 _mainpanel.getCurrentTreePanel().setEdited( true );
1401 final int poly = PhylogenyMethods.countNumberOfPolytomies( species_tree );
1402 if ( gsdi.getStrippedExternalGeneTreeNodes().size() > 0 ) {
1403 JOptionPane.showMessageDialog( this,
1404 "Duplications: " + gsdi.getDuplicationsSum() + "\n"
1405 + "Potential duplications: "
1406 + gsdi.getSpeciationOrDuplicationEventsSum() + "\n"
1407 + "Speciations: " + gsdi.getSpeciationsSum() + "\n"
1408 + "Stripped gene tree nodes: "
1409 + gsdi.getStrippedExternalGeneTreeNodes().size() + "\n"
1410 + "Taxonomy linkage based on: " + gsdi.getTaxCompBase() + "\n"
1411 + "Number of polytomies in species tree used: " + poly + "\n",
1412 "GSDI successfully completed",
1413 JOptionPane.WARNING_MESSAGE );
1416 JOptionPane.showMessageDialog( this,
1417 "Duplications: " + gsdi.getDuplicationsSum() + "\n"
1418 + "Potential duplications: "
1419 + gsdi.getSpeciationOrDuplicationEventsSum() + "\n"
1420 + "Speciations: " + gsdi.getSpeciationsSum() + "\n"
1421 + "Stripped gene tree nodes: "
1422 + gsdi.getStrippedExternalGeneTreeNodes().size() + "\n"
1423 + "Taxonomy linkage based on: " + gsdi.getTaxCompBase() + "\n"
1424 + "Number of polytomies in species tree used: " + poly + "\n",
1425 "GSDI successfully completed",
1426 JOptionPane.INFORMATION_MESSAGE );
1430 void executeGSDIR() {
1431 if ( !isOKforSDI( false, false ) ) {
1434 final int p = PhylogenyMethods.countNumberOfPolytomies( _mainpanel.getCurrentPhylogeny() );
1436 && !( ( p == 1 ) && ( _mainpanel.getCurrentPhylogeny().getRoot().getNumberOfDescendants() == 3 ) ) ) {
1437 JOptionPane.showMessageDialog( this,
1438 "Gene tree is not completely binary",
1439 "Cannot execute GSDI",
1440 JOptionPane.ERROR_MESSAGE );
1443 final Phylogeny gene_tree = _mainpanel.getCurrentPhylogeny().copy();
1444 gene_tree.setAllNodesToNotCollapse();
1445 gene_tree.recalculateNumberOfExternalDescendants( false );
1447 final Phylogeny species_tree = _species_tree.copy();
1449 gsdir = new GSDIR( gene_tree, species_tree, true, true, true );
1451 catch ( final SDIException e ) {
1452 JOptionPane.showMessageDialog( this,
1453 e.getLocalizedMessage(),
1454 "Error during GSDIR",
1455 JOptionPane.ERROR_MESSAGE );
1458 catch ( final Exception e ) {
1459 AptxUtil.unexpectedException( e );
1462 final Phylogeny result_gene_tree = gsdir.getMinDuplicationsSumGeneTree();
1463 result_gene_tree.setRerootable( false );
1464 result_gene_tree.clearHashIdToNodeMap();
1465 result_gene_tree.recalculateNumberOfExternalDescendants( true );
1466 PhylogenyMethods.orderAppearance( result_gene_tree.getRoot(), true, true, DESCENDANT_SORT_PRIORITY.NODE_NAME );
1467 _mainpanel.addPhylogenyInNewTab( result_gene_tree, getConfiguration(), "gene tree", null );
1468 getMainPanel().getControlPanel().setShowEvents( true );
1470 final int selected = _mainpanel.getTabbedPane().getSelectedIndex();
1471 _mainpanel.addPhylogenyInNewTab( species_tree, getConfiguration(), "species tree", null );
1473 _mainpanel.getTabbedPane().setSelectedIndex( selected );
1475 _mainpanel.getCurrentTreePanel().setEdited( true );
1476 final int poly = PhylogenyMethods.countNumberOfPolytomies( species_tree );
1477 if ( gsdir.getStrippedExternalGeneTreeNodes().size() > 0 ) {
1478 JOptionPane.showMessageDialog( this,
1479 "Minimal duplications: " + gsdir.getMinDuplicationsSum() + "\n"
1480 + "Speciations: " + gsdir.getSpeciationsSum() + "\n"
1481 + "Stripped gene tree nodes: "
1482 + gsdir.getStrippedExternalGeneTreeNodes().size() + "\n"
1483 + "Taxonomy linkage based on: " + gsdir.getTaxCompBase() + "\n"
1484 + "Number of polytomies in species tree used: " + poly + "\n",
1485 "GSDIR successfully completed",
1486 JOptionPane.WARNING_MESSAGE );
1489 JOptionPane.showMessageDialog( this,
1490 "Minimal duplications: " + gsdir.getMinDuplicationsSum() + "\n"
1491 + "Speciations: " + gsdir.getSpeciationsSum() + "\n"
1492 + "Stripped gene tree nodes: "
1493 + gsdir.getStrippedExternalGeneTreeNodes().size() + "\n"
1494 + "Taxonomy linkage based on: " + gsdir.getTaxCompBase() + "\n"
1495 + "Number of polytomies in species tree used: " + poly + "\n",
1496 "GSDIR successfully completed",
1497 JOptionPane.INFORMATION_MESSAGE );
1501 Configuration getConfiguration() {
1502 return _configuration;
1505 File getCurrentDir() {
1506 if ( ( _current_dir == null ) || !_current_dir.canRead() ) {
1507 if ( ForesterUtil.isWindows() ) {
1509 _current_dir = new File( WindowsUtils.getCurrentUserDesktopPath() );
1511 catch ( final Exception e ) {
1512 _current_dir = null;
1516 if ( ( _current_dir == null ) || !_current_dir.canRead() ) {
1517 if ( System.getProperty( "user.home" ) != null ) {
1518 _current_dir = new File( System.getProperty( "user.home" ) );
1520 else if ( System.getProperty( "user.dir" ) != null ) {
1521 _current_dir = new File( System.getProperty( "user.dir" ) );
1524 return _current_dir;
1527 TreePanel getCurrentTreePanel() {
1528 return getMainPanel().getCurrentTreePanel();
1531 JCheckBoxMenuItem getlabelDirectionCbmi() {
1532 return _label_direction_cbmi;
1535 MainPanel getMainPanel() {
1539 Options getOtions() {
1543 void initializeTypeMenu( final Options options ) {
1544 setTypeMenuToAllUnselected();
1546 switch ( options.getPhylogenyGraphicsType() ) {
1548 _convex_type_cbmi.setSelected( true );
1551 _curved_type_cbmi.setSelected( true );
1554 _euro_type_cbmi.setSelected( true );
1557 _rounded_type_cbmi.setSelected( true );
1560 _triangular_type_cbmi.setSelected( true );
1563 _unrooted_type_cbmi.setSelected( true );
1566 _circular_type_cbmi.setSelected( true );
1569 _rectangular_type_cbmi.setSelected( true );
1573 catch ( final NullPointerException np ) {
1574 // In all likelihood, this is caused by menu-less display.
1578 boolean isOKforSDI( final boolean species_tree_has_to_binary, final boolean gene_tree_has_to_binary ) {
1579 if ( ( _mainpanel.getCurrentPhylogeny() == null ) || _mainpanel.getCurrentPhylogeny().isEmpty() ) {
1582 else if ( ( _species_tree == null ) || _species_tree.isEmpty() ) {
1583 JOptionPane.showMessageDialog( this,
1584 "No species tree loaded",
1585 "Cannot execute GSDI",
1586 JOptionPane.ERROR_MESSAGE );
1589 else if ( species_tree_has_to_binary && !_species_tree.isCompletelyBinary() ) {
1590 JOptionPane.showMessageDialog( this,
1591 "Species tree is not completely binary",
1592 "Cannot execute GSDI",
1593 JOptionPane.ERROR_MESSAGE );
1596 else if ( gene_tree_has_to_binary && !_mainpanel.getCurrentPhylogeny().isCompletelyBinary() ) {
1597 JOptionPane.showMessageDialog( this,
1598 "Gene tree is not completely binary",
1599 "Cannot execute GSDI",
1600 JOptionPane.ERROR_MESSAGE );
1608 boolean isSubtreeDisplayed() {
1609 if ( getCurrentTreePanel() != null ) {
1610 if ( getCurrentTreePanel().isCurrentTreeIsSubtree() ) {
1612 .showMessageDialog( this,
1613 "This operation can only be performed on a complete tree, not on the currently displayed sub-tree only.",
1614 "Operation can not be exectuted on a sub-tree",
1615 JOptionPane.WARNING_MESSAGE );
1622 void removeAllTextFrames() {
1623 for( final TextFrame tf : _textframes ) {
1628 _textframes.clear();
1631 void setConfiguration( final Configuration configuration ) {
1632 _configuration = configuration;
1635 void setCurrentDir( final File current_dir ) {
1636 _current_dir = current_dir;
1639 void setOptions( final Options options ) {
1643 void setSelectedTypeInTypeMenu( final PHYLOGENY_GRAPHICS_TYPE type ) {
1644 setTypeMenuToAllUnselected();
1648 _circular_type_cbmi.setSelected( true );
1651 _convex_type_cbmi.setSelected( true );
1654 _curved_type_cbmi.setSelected( true );
1657 _euro_type_cbmi.setSelected( true );
1660 _rounded_type_cbmi.setSelected( true );
1663 _rectangular_type_cbmi.setSelected( true );
1666 _triangular_type_cbmi.setSelected( true );
1669 _unrooted_type_cbmi.setSelected( true );
1672 throw new IllegalArgumentException( "unknown type: " + type );
1675 catch ( final NullPointerException np ) {
1676 // In all likelihood, this is caused by menu-less display.
1680 void setTypeMenuToAllUnselected() {
1681 if ( _convex_type_cbmi != null ) {
1682 _convex_type_cbmi.setSelected( false );
1684 if ( _curved_type_cbmi != null ) {
1685 _curved_type_cbmi.setSelected( false );
1687 if ( _euro_type_cbmi != null ) {
1688 _euro_type_cbmi.setSelected( false );
1690 if ( _rounded_type_cbmi != null ) {
1691 _rounded_type_cbmi.setSelected( false );
1693 if ( _triangular_type_cbmi != null ) {
1694 _triangular_type_cbmi.setSelected( false );
1696 if ( _rectangular_type_cbmi != null ) {
1697 _rectangular_type_cbmi.setSelected( false );
1699 if ( _unrooted_type_cbmi != null ) {
1700 _unrooted_type_cbmi.setSelected( false );
1702 if ( _circular_type_cbmi != null ) {
1703 _circular_type_cbmi.setSelected( false );
1708 _mainpanel.getControlPanel().showWhole();
1711 void switchColors() {
1712 final TreeColorSet colorset = getMainPanel().getCurrentTreePanel().getTreeColorSet();
1713 final ColorSchemeChooser csc = new ColorSchemeChooser( getMainPanel(), colorset );
1714 csc.setVisible( true );
1715 getMainPanel().setTreeColorSet( colorset );
1718 void typeChanged( final Object o ) {
1719 updateTypeCheckboxes( getOptions(), o );
1720 updateOptions( getOptions() );
1721 if ( getCurrentTreePanel() != null ) {
1722 final PHYLOGENY_GRAPHICS_TYPE previous_type = getCurrentTreePanel().getPhylogenyGraphicsType();
1723 final PHYLOGENY_GRAPHICS_TYPE new_type = getOptions().getPhylogenyGraphicsType();
1724 if ( ( ( previous_type == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) && ( new_type != PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) )
1725 || ( ( previous_type == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) && ( new_type != PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) )
1726 || ( ( previous_type != PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) && ( new_type == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) )
1727 || ( ( previous_type != PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) && ( new_type == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) ) ) {
1728 getCurrentTreePanel().getControlPanel().showWhole();
1730 if ( getCurrentTreePanel().isPhyHasBranchLengths() && ( new_type != PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) ) {
1731 getCurrentTreePanel().getControlPanel().setDrawPhylogramEnabled( true );
1734 getCurrentTreePanel().getControlPanel().setDrawPhylogramEnabled( false );
1736 getCurrentTreePanel().setPhylogenyGraphicsType( getOptions().getPhylogenyGraphicsType() );
1737 MainFrame.updateScreenTextAntialias( getMainPanel().getTreePanels() );
1741 void updateOptions( final Options options ) {
1742 options.setAntialiasScreen( ( _screen_antialias_cbmi != null ) && _screen_antialias_cbmi.isSelected() );
1743 options.setBackgroundColorGradient( ( _background_gradient_cbmi != null )
1744 && _background_gradient_cbmi.isSelected() );
1745 options.setShowDomainLabels( ( _show_domain_labels != null ) && _show_domain_labels.isSelected() );
1746 options.setShowAnnotationRefSource( ( _show_annotation_ref_source != null )
1747 && _show_annotation_ref_source.isSelected() );
1748 options.setAbbreviateScientificTaxonNames( ( _abbreviate_scientific_names != null )
1749 && _abbreviate_scientific_names.isSelected() );
1750 options.setColorLabelsSameAsParentBranch( ( _color_labels_same_as_parent_branch != null )
1751 && _color_labels_same_as_parent_branch.isSelected() );
1752 options.setShowDefaultNodeShapesInternal( ( _show_default_node_shapes_internal_cbmi != null )
1753 && _show_default_node_shapes_internal_cbmi.isSelected() );
1754 options.setShowDefaultNodeShapesExternal( ( _show_default_node_shapes_external_cbmi != null )
1755 && _show_default_node_shapes_external_cbmi.isSelected() );
1756 options.setShowDefaultNodeShapesForMarkedNodes( ( _show_default_node_shapes_for_marked_cbmi != null )
1757 && _show_default_node_shapes_for_marked_cbmi.isSelected() );
1758 if ( ( _non_lined_up_cladograms_rbmi != null ) && ( _non_lined_up_cladograms_rbmi.isSelected() ) ) {
1759 options.setCladogramType( CLADOGRAM_TYPE.NON_LINED_UP );
1761 else if ( ( _uniform_cladograms_rbmi != null ) && ( _uniform_cladograms_rbmi.isSelected() ) ) {
1762 options.setCladogramType( CLADOGRAM_TYPE.TOTAL_NODE_SUM_DEP );
1764 else if ( ( _ext_node_dependent_cladogram_rbmi != null ) && ( _ext_node_dependent_cladogram_rbmi.isSelected() ) ) {
1765 options.setCladogramType( CLADOGRAM_TYPE.EXT_NODE_SUM_DEP );
1767 options.setSearchCaseSensitive( ( _search_case_senstive_cbmi != null )
1768 && _search_case_senstive_cbmi.isSelected() );
1769 if ( ( _show_scale_cbmi != null ) && _show_scale_cbmi.isEnabled() ) {
1770 options.setShowScale( _show_scale_cbmi.isSelected() );
1772 if ( _label_direction_cbmi != null ) {
1773 if ( _label_direction_cbmi.isSelected() ) {
1774 options.setNodeLabelDirection( NODE_LABEL_DIRECTION.RADIAL );
1777 options.setNodeLabelDirection( NODE_LABEL_DIRECTION.HORIZONTAL );
1780 options.setShowOverview( ( _show_overview_cbmi != null ) && _show_overview_cbmi.isSelected() );
1781 options.setShowConfidenceStddev( ( _show_confidence_stddev_cbmi != null )
1782 && _show_confidence_stddev_cbmi.isSelected() );
1783 options.setMatchWholeTermsOnly( ( _search_whole_words_only_cbmi != null )
1784 && _search_whole_words_only_cbmi.isSelected() );
1785 options.setSearchWithRegex( ( _search_with_regex_cbmi != null ) && _search_with_regex_cbmi.isSelected() );
1786 options.setInverseSearchResult( ( _inverse_search_result_cbmi != null )
1787 && _inverse_search_result_cbmi.isSelected() );
1788 options.setPrintUsingActualSize( ( _print_using_actual_size_cbmi != null )
1789 && ( _print_using_actual_size_cbmi.isSelected() ) );
1790 options.setGraphicsExportUsingActualSize( ( _graphics_export_using_actual_size_cbmi != null )
1791 && ( _graphics_export_using_actual_size_cbmi.isSelected() ) );
1792 options.setAntialiasPrint( ( _antialias_print_cbmi != null ) && _antialias_print_cbmi.isSelected() );
1793 options.setPrintBlackAndWhite( ( _print_black_and_white_cbmi != null )
1794 && _print_black_and_white_cbmi.isSelected() );
1795 if ( ( _rectangular_type_cbmi != null ) && _rectangular_type_cbmi.isSelected() ) {
1796 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR );
1798 else if ( ( _triangular_type_cbmi != null ) && _triangular_type_cbmi.isSelected() ) {
1799 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.TRIANGULAR );
1801 else if ( ( _curved_type_cbmi != null ) && _curved_type_cbmi.isSelected() ) {
1802 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CURVED );
1804 else if ( ( _convex_type_cbmi != null ) && _convex_type_cbmi.isSelected() ) {
1805 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CONVEX );
1807 else if ( ( _euro_type_cbmi != null ) && _euro_type_cbmi.isSelected() ) {
1808 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE );
1810 else if ( ( _rounded_type_cbmi != null ) && _rounded_type_cbmi.isSelected() ) {
1811 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.ROUNDED );
1813 else if ( ( _unrooted_type_cbmi != null ) && _unrooted_type_cbmi.isSelected() ) {
1814 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.UNROOTED );
1816 else if ( ( _circular_type_cbmi != null ) && _circular_type_cbmi.isSelected() ) {
1817 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CIRCULAR );
1819 if ( ( _color_by_taxonomic_group_cbmi != null ) && _color_by_taxonomic_group_cbmi.isEnabled() ) {
1820 options.setColorByTaxonomicGroup( _color_by_taxonomic_group_cbmi.isSelected() );
1822 if ( ( _right_line_up_domains_cbmi != null ) && _right_line_up_domains_cbmi.isEnabled() ) {
1823 options.setRightLineUpDomains( _right_line_up_domains_cbmi.isSelected() );
1825 if ( ( _line_up_renderable_data_cbmi != null ) && _line_up_renderable_data_cbmi.isEnabled() ) {
1826 options.setLineUpRendarableNodeData( _line_up_renderable_data_cbmi.isSelected() );
1828 if ( _graphics_export_visible_only_cbmi != null ) {
1829 options.setGraphicsExportVisibleOnly( _graphics_export_visible_only_cbmi.isSelected() );
1830 if ( _graphics_export_visible_only_cbmi.isSelected() && ( _graphics_export_using_actual_size_cbmi != null ) ) {
1831 _graphics_export_using_actual_size_cbmi.setSelected( true );
1832 _graphics_export_using_actual_size_cbmi.setEnabled( false );
1835 _graphics_export_using_actual_size_cbmi.setEnabled( true );
1840 void updateTypeCheckboxes( final Options options, final Object o ) {
1841 setTypeMenuToAllUnselected();
1842 ( ( JCheckBoxMenuItem ) o ).setSelected( true );
1845 void viewAsNexus() {
1846 if ( ( getMainPanel().getCurrentPhylogeny() != null ) && !getMainPanel().getCurrentPhylogeny().isEmpty() ) {
1847 String title = "Nexus";
1848 if ( !ForesterUtil.isEmpty( getMainPanel().getCurrentPhylogeny().getName() ) ) {
1849 title = "\"" + getMainPanel().getCurrentPhylogeny().getName() + "\" in " + title;
1851 showTextFrame( getMainPanel().getCurrentPhylogeny().toNexus( getOptions()
1852 .getNhConversionSupportValueStyle() ),
1858 if ( ( getMainPanel().getCurrentPhylogeny() != null ) && !getMainPanel().getCurrentPhylogeny().isEmpty() ) {
1859 String title = "New Hampshire";
1860 if ( !ForesterUtil.isEmpty( getMainPanel().getCurrentPhylogeny().getName() ) ) {
1861 title = "\"" + getMainPanel().getCurrentPhylogeny().getName() + "\" in " + title;
1863 showTextFrame( getMainPanel().getCurrentPhylogeny().toNewHampshire( getOptions()
1864 .getNhConversionSupportValueStyle() ),
1870 if ( ( getMainPanel().getCurrentPhylogeny() != null ) && !getMainPanel().getCurrentPhylogeny().isEmpty() ) {
1871 String title = "phyloXML";
1872 if ( !ForesterUtil.isEmpty( getMainPanel().getCurrentPhylogeny().getName() ) ) {
1873 title = "\"" + getMainPanel().getCurrentPhylogeny().getName() + "\" in " + title;
1875 showTextFrame( getMainPanel().getCurrentPhylogeny().toPhyloXML( 0 ), title );
1879 static void setTextForGraphicsSizeChooserMenuItem( final JMenuItem mi, final Options o ) {
1880 mi.setText( "Enter Default Size for Graphics Export... (current: " + o.getPrintSizeX() + ", "
1881 + o.getPrintSizeY() + ")" );
1884 static void setTextForPdfLineWidthChooserMenuItem( final JMenuItem mi, final Options o ) {
1885 mi.setText( "Enter Default Line Width for PDF Export... (current: " + o.getPrintLineWidth() + ")" );
1888 static void setupScreenTextAntialias( final List<TreePanel> treepanels, final boolean antialias ) {
1889 for( final TreePanel tree_panel : treepanels ) {
1890 tree_panel.setTextAntialias();