2 // FORESTER -- software libraries and applications
3 // for evolutionary biology research and applications.
5 // Copyright (C) 2008-2010 Christian M. Zmasek
8 // This library is free software; you can redistribute it and/or
9 // modify it under the terms of the GNU Lesser General Public
10 // License as published by the Free Software Foundation; either
11 // version 2.1 of the License, or (at your option) any later version.
13 // This library is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 // Lesser General Public License for more details.
18 // You should have received a copy of the GNU Lesser General Public
19 // License along with this library; if not, write to the Free Software
20 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 // Contact: phylosoft @ gmail . com
23 // WWW: https://sites.google.com/site/cmzmasek/home/software/forester
25 package org.forester.archaeopteryx;
27 import java.awt.Color;
28 import java.awt.Component;
29 import java.awt.Container;
31 import java.awt.event.ActionEvent;
32 import java.awt.event.ActionListener;
34 import java.io.IOException;
35 import java.util.ArrayList;
36 import java.util.LinkedList;
37 import java.util.List;
38 import java.util.Locale;
39 import java.util.NoSuchElementException;
41 import javax.swing.Box;
42 import javax.swing.JApplet;
43 import javax.swing.JCheckBoxMenuItem;
44 import javax.swing.JFileChooser;
45 import javax.swing.JFrame;
46 import javax.swing.JLabel;
47 import javax.swing.JMenu;
48 import javax.swing.JMenuBar;
49 import javax.swing.JMenuItem;
50 import javax.swing.JOptionPane;
51 import javax.swing.JPanel;
52 import javax.swing.JRadioButtonMenuItem;
53 import javax.swing.JTextField;
54 import javax.swing.SwingUtilities;
55 import javax.swing.filechooser.FileFilter;
57 import org.forester.archaeopteryx.AptxUtil.GraphicsExportType;
58 import org.forester.archaeopteryx.Options.CLADOGRAM_TYPE;
59 import org.forester.archaeopteryx.Options.NODE_LABEL_DIRECTION;
60 import org.forester.archaeopteryx.Options.PHYLOGENY_GRAPHICS_TYPE;
61 import org.forester.archaeopteryx.tools.AncestralTaxonomyInferrer;
62 import org.forester.archaeopteryx.tools.InferenceManager;
63 import org.forester.archaeopteryx.tools.ProcessPool;
64 import org.forester.archaeopteryx.tools.ProcessRunning;
65 import org.forester.io.parsers.nhx.NHXParser.TAXONOMY_EXTRACTION;
66 import org.forester.io.writers.PhylogenyWriter;
67 import org.forester.phylogeny.Phylogeny;
68 import org.forester.phylogeny.PhylogenyMethods;
69 import org.forester.phylogeny.PhylogenyMethods.DESCENDANT_SORT_PRIORITY;
70 import org.forester.phylogeny.PhylogenyNode;
71 import org.forester.phylogeny.PhylogenyNode.NH_CONVERSION_SUPPORT_VALUE_STYLE;
72 import org.forester.phylogeny.data.Annotation;
73 import org.forester.phylogeny.data.NodeDataField;
74 import org.forester.phylogeny.data.NodeVisualData.NodeFill;
75 import org.forester.phylogeny.data.NodeVisualData.NodeShape;
76 import org.forester.phylogeny.iterators.PhylogenyNodeIterator;
77 import org.forester.sdi.GSDI;
78 import org.forester.sdi.GSDIR;
79 import org.forester.sdi.SDIException;
80 import org.forester.util.ForesterConstants;
81 import org.forester.util.ForesterUtil;
82 import org.forester.util.WindowsUtils;
84 public abstract class MainFrame extends JFrame implements ActionListener {
86 final static NHFilter nhfilter = new NHFilter();
87 final static NHXFilter nhxfilter = new NHXFilter();
88 final static XMLFilter xmlfilter = new XMLFilter();
89 final static TolFilter tolfilter = new TolFilter();
90 final static NexusFilter nexusfilter = new NexusFilter();
91 final static PdfFilter pdffilter = new PdfFilter();
92 final static GraphicsFileFilter graphicsfilefilter = new GraphicsFileFilter();
93 final static MsaFileFilter msafilter = new MsaFileFilter();
94 final static SequencesFileFilter seqsfilter = new SequencesFileFilter();
95 final static DefaultFilter defaultfilter = new DefaultFilter();
96 static final String USE_MOUSEWHEEL_SHIFT_TO_ROTATE = "In this display type, use mousewheel + Shift to rotate [or A and S]";
97 static final String PHYLOXML_REF_TOOL_TIP = AptxConstants.PHYLOXML_REFERENCE; //TODO //FIXME
98 static final String APTX_REF_TOOL_TIP = AptxConstants.APTX_REFERENCE;
99 private static final long serialVersionUID = 3655000897845508358L;
100 final static Font menu_font = new Font( Configuration.getDefaultFontFamilyName(),
103 static final String TYPE_MENU_HEADER = "Type";
104 static final String RECTANGULAR_TYPE_CBMI_LABEL = "Rectangular";
105 static final String EURO_TYPE_CBMI_LABEL = "Euro Type";
106 static final String CURVED_TYPE_CBMI_LABEL = "Curved";
107 static final String TRIANGULAR_TYPE_CBMI_LABEL = "Triangular";
108 static final String CONVEX_TYPE_CBMI_LABEL = "Convex";
109 static final String ROUNDED_TYPE_CBMI_LABEL = "Rounded";
110 static final String UNROOTED_TYPE_CBMI_LABEL = "Unrooted (alpha)"; //TODO
111 static final String CIRCULAR_TYPE_CBMI_LABEL = "Circular (alpha)"; //TODO
112 static final String OPTIONS_HEADER = "Options";
113 static final String SEARCH_SUBHEADER = "Search:";
114 static final String DISPLAY_SUBHEADER = "Display:";
115 static final String SEARCH_TERMS_ONLY_LABEL = "Match Complete Terms Only";
116 static final String SEARCH_REGEX_LABEL = "Search with Regular Expressions";
117 static final String SEARCH_CASE_SENSITIVE_LABEL = "Case Sensitive";
118 static final String INVERSE_SEARCH_RESULT_LABEL = "Negate Result";
119 static final String COLOR_BY_TAXONOMIC_GROUP = "Colorize by Taxonomic Group";
120 static final String DISPLAY_SCALE_LABEL = "Scale";
121 static final String NON_LINED_UP_CLADOGRAMS_LABEL = "Non-Lined Up Cladograms";
122 static final String UNIFORM_CLADOGRAMS_LABEL = "Total Node Sum Dependent Cladograms";
123 static final String LABEL_DIRECTION_LABEL = "Radial Labels";
124 static final String LABEL_DIRECTION_TIP = "To use radial node labels in radial and unrooted display types";
125 static final String SEARCH_WITH_REGEX_TIP = "To search using regular expressions (~Java/Perl syntax). For example, use \"^B.+\\d{2,}$\" to search for everything starting with a B and ending with at least two digits.";
126 static final String SCREEN_ANTIALIAS_LABEL = "Antialias";
127 static final String COLOR_LABELS_LABEL = "Colorize Labels Same as Parent Branch";
128 static final String BG_GRAD_LABEL = "Background Color Gradient";
129 static final String DISPLAY_NODE_BOXES_LABEL_EXT = "Shapes for External Nodes";
130 static final String DISPLAY_NODE_BOXES_LABEL_INT = "Shapes for Internal Nodes";
131 static final String DISPLAY_NODE_BOXES_LABEL_MARKED = "Shapes for Nodes with Visual Data";
132 static final String SHOW_OVERVIEW_LABEL = "Overview";
133 static final String FONT_SIZE_MENU_LABEL = "Font Size";
134 static final String NONUNIFORM_CLADOGRAMS_LABEL = "External Node Sum Dependent Cladograms";
135 static final String SHOW_DOMAIN_LABELS_LABEL = "Domain Labels";
136 static final String SHOW_ANN_REF_SOURCE_LABEL = "Seq Annotation Ref Sources";
137 static final String COLOR_LABELS_TIP = "To use parent branch colors for node labels as well, need to turn off taxonomy dependent colorization and turn on branch colorization for this to become apparent";
138 static final String ABBREV_SN_LABEL = "Abbreviate Scientific Taxonomic Names";
139 static final String TAXONOMY_COLORIZE_NODE_SHAPES_LABEL = "Colorize Node Shapes According to Taxonomy";
140 static final String CYCLE_NODE_SHAPE_LABEL = "Cycle Node Shapes";
141 static final String CYCLE_NODE_FILL_LABEL = "Cycle Node Fill Type";
142 static final String CHOOSE_NODE_SIZE_LABEL = "Choose Node Shape Size";
143 static final String SHOW_CONF_STDDEV_LABEL = "Confidence Standard Deviations";
144 static final String USE_BRACKETS_FOR_CONF_IN_NH_LABEL = "Use Brackets for Confidence Values";
145 static final String USE_INTERNAL_NAMES_FOR_CONF_IN_NH_LABEL = "Use Internal Node Names for Confidence Values";
146 static final String SHOW_BASIC_TREE_INFORMATION_LABEL = "Basic Tree Information";
147 static final String RIGHT_LINE_UP_DOMAINS = "Right-align Domain Architectures";
148 static final String LINE_UP_RENDERABLE_DATA = "Line Up Diagrams (such as Domain Architectures)";
149 static final String INFER_ANCESTOR_TAXONOMIES = "Infer Ancestor Taxonomies";
150 static final String OBTAIN_DETAILED_TAXONOMIC_INFORMATION = "Obtain Detailed Taxonomic Information";
155 JMenu _options_jmenu;
156 JMenu _font_size_menu;
158 JMenuItem[] _load_phylogeny_from_webservice_menu_items;
160 JMenu _analysis_menu;
161 JMenuItem _load_species_tree_item;
162 JMenuItem _gsdi_item;
163 JMenuItem _gsdir_item;
164 JMenuItem _lineage_inference;
166 JMenuItem _open_item;
167 JMenuItem _open_url_item;
168 JMenuItem _save_item;
169 JMenuItem _save_all_item;
170 JMenuItem _close_item;
171 JMenuItem _exit_item;
173 JMenuItem _print_item;
174 JMenuItem _write_to_pdf_item;
175 JMenuItem _write_to_jpg_item;
176 JMenuItem _write_to_gif_item;
177 JMenuItem _write_to_tif_item;
178 JMenuItem _write_to_png_item;
179 JMenuItem _write_to_bmp_item;
181 JMenuItem _midpoint_root_item;
182 JMenuItem _taxcolor_item;
183 JMenuItem _confcolor_item;
184 JMenuItem _color_rank_jmi;
185 JMenuItem _collapse_species_specific_subtrees;
186 JMenuItem _obtain_detailed_taxonomic_information_jmi;
187 JMenuItem _obtain_detailed_taxonomic_information_deleting_jmi;
188 JMenuItem _obtain_seq_information_jmi;
189 JMenuItem _move_node_names_to_tax_sn_jmi;
190 JMenuItem _move_node_names_to_seq_names_jmi;
191 JMenuItem _extract_tax_code_from_node_names_jmi;
192 JMenuItem _annotate_item;
193 JMenuItem _remove_branch_color_item;
194 JMenuItem _remove_visual_styles_item;
195 JMenuItem _delete_selected_nodes_item;
196 JMenuItem _delete_not_selected_nodes_item;
198 JMenuItem _super_tiny_fonts_item;
199 JMenuItem _tiny_fonts_item;
200 JMenuItem _small_fonts_item;
201 JMenuItem _medium_fonts_item;
202 JMenuItem _large_fonts_item;
204 // _ screen and print
205 JMenuItem _choose_font_mi;
206 JMenuItem _switch_colors_mi;
207 JCheckBoxMenuItem _label_direction_cbmi;
209 JCheckBoxMenuItem _screen_antialias_cbmi;
210 JCheckBoxMenuItem _background_gradient_cbmi;
211 JRadioButtonMenuItem _non_lined_up_cladograms_rbmi;
212 JRadioButtonMenuItem _uniform_cladograms_rbmi;
213 JRadioButtonMenuItem _ext_node_dependent_cladogram_rbmi;
214 JCheckBoxMenuItem _color_by_taxonomic_group_cbmi;
215 JCheckBoxMenuItem _show_scale_cbmi; //TODO fix me
216 JCheckBoxMenuItem _show_overview_cbmi;
217 JCheckBoxMenuItem _show_domain_labels;
218 JCheckBoxMenuItem _show_annotation_ref_source;
219 JCheckBoxMenuItem _abbreviate_scientific_names;
220 JCheckBoxMenuItem _color_labels_same_as_parent_branch;
221 JMenuItem _overview_placment_mi;
222 JMenuItem _choose_minimal_confidence_mi;
223 JCheckBoxMenuItem _show_default_node_shapes_internal_cbmi;
224 JCheckBoxMenuItem _show_default_node_shapes_external_cbmi;
225 JCheckBoxMenuItem _show_default_node_shapes_for_marked_cbmi;
226 JMenuItem _cycle_node_shape_mi;
227 JMenuItem _cycle_node_fill_mi;
228 JMenuItem _choose_node_size_mi;
229 JMenuItem _cycle_data_return;
230 JCheckBoxMenuItem _show_confidence_stddev_cbmi;
231 JCheckBoxMenuItem _right_line_up_domains_cbmi;
232 JCheckBoxMenuItem _line_up_renderable_data_cbmi;
234 JCheckBoxMenuItem _graphics_export_visible_only_cbmi;
235 JCheckBoxMenuItem _antialias_print_cbmi;
236 JCheckBoxMenuItem _print_black_and_white_cbmi;
237 //JMenuItem _print_size_mi;
238 JMenuItem _choose_pdf_width_mi;
240 JCheckBoxMenuItem _internal_number_are_confidence_for_nh_parsing_cbmi;
241 JRadioButtonMenuItem _extract_taxonomy_no_rbmi;
242 JRadioButtonMenuItem _extract_taxonomy_agressive_rbmi;
243 JRadioButtonMenuItem _extract_taxonomy_pfam_strict_rbmi;
244 JRadioButtonMenuItem _extract_taxonomy_pfam_relaxed_rbmi;
245 JCheckBoxMenuItem _replace_underscores_cbmi;
246 JCheckBoxMenuItem _allow_errors_in_distance_to_parent_cbmi;
247 JCheckBoxMenuItem _use_brackets_for_conf_in_nh_export_cbmi;
248 JCheckBoxMenuItem _use_internal_names_for_conf_in_nh_export_cbmi;
249 JCheckBoxMenuItem _parse_beast_style_extended_nexus_tags_cbmi;
251 JCheckBoxMenuItem _search_case_senstive_cbmi;
252 JCheckBoxMenuItem _search_whole_words_only_cbmi;
253 JCheckBoxMenuItem _inverse_search_result_cbmi;
254 JCheckBoxMenuItem _search_with_regex_cbmi;
255 JCheckBoxMenuItem _color_all_found_nodes_when_coloring_subtree_cbmi;
258 JCheckBoxMenuItem _rectangular_type_cbmi;
259 JCheckBoxMenuItem _triangular_type_cbmi;
260 JCheckBoxMenuItem _curved_type_cbmi;
261 JCheckBoxMenuItem _convex_type_cbmi;
262 JCheckBoxMenuItem _euro_type_cbmi;
263 JCheckBoxMenuItem _rounded_type_cbmi;
264 JCheckBoxMenuItem _unrooted_type_cbmi;
265 JCheckBoxMenuItem _circular_type_cbmi;
266 // view as text menu:
267 JMenuItem _view_as_NH_item;
268 JMenuItem _view_as_XML_item;
269 JMenuItem _view_as_nexus_item;
270 JMenuItem _display_basic_information_item;
272 JMenuItem _about_item;
273 JMenuItem _help_item;
274 JMenuItem _website_item;
275 JMenuItem _phyloxml_website_item;
276 JMenuItem _phyloxml_ref_item;
277 JMenuItem _aptx_ref_item;
280 JFileChooser _writetopdf_filechooser;
281 JFileChooser _save_filechooser;
282 JFileChooser _writetographics_filechooser;
285 MainPanel _mainpanel;
286 Container _contentpane;
287 final LinkedList<TextFrame> _textframes = new LinkedList<TextFrame>(); ;
288 Configuration _configuration;
290 private Phylogeny _species_tree;
291 InferenceManager _inference_manager;
292 final ProcessPool _process_pool;
293 private String _previous_node_annotation_ref;
296 _process_pool = ProcessPool.createInstance();
297 _writetopdf_filechooser = new JFileChooser();
298 _writetopdf_filechooser.setMultiSelectionEnabled( false );
299 _writetopdf_filechooser.addChoosableFileFilter( pdffilter );
300 _writetographics_filechooser = new JFileChooser();
301 _writetographics_filechooser.setMultiSelectionEnabled( false );
302 _writetographics_filechooser.addChoosableFileFilter( graphicsfilefilter );
303 _save_filechooser = new JFileChooser();
304 _save_filechooser.setMultiSelectionEnabled( false );
305 _save_filechooser.setFileFilter( xmlfilter );
306 _save_filechooser.addChoosableFileFilter( nhfilter );
307 _save_filechooser.addChoosableFileFilter( nexusfilter );
308 _save_filechooser.addChoosableFileFilter( _save_filechooser.getAcceptAllFileFilter() );
310 final String home_dir = System.getProperty( "user.home" );
311 _save_filechooser.setCurrentDirectory( new File( home_dir ) );
312 _writetopdf_filechooser.setCurrentDirectory( new File( home_dir ) );
313 _writetographics_filechooser.setCurrentDirectory( new File( home_dir ) );
315 catch ( final Exception e ) {
317 // Do nothing. Not important.
325 public void actionPerformed( final ActionEvent e ) {
326 final Object o = e.getSource();
327 boolean is_applet = false;
328 JApplet applet = null;
329 if ( getCurrentTreePanel() != null ) {
330 is_applet = getCurrentTreePanel().isApplet();
332 applet = getCurrentTreePanel().obtainApplet();
335 if ( o == _exit_item ) {
338 else if ( o == _gsdi_item ) {
339 if ( isSubtreeDisplayed() ) {
344 else if ( o == _gsdir_item ) {
345 if ( isSubtreeDisplayed() ) {
350 else if ( o == _taxcolor_item ) {
353 else if ( o == _confcolor_item ) {
356 else if ( o == _color_rank_jmi ) {
359 else if ( o == _collapse_species_specific_subtrees ) {
360 if ( isSubtreeDisplayed() ) {
363 if ( getCurrentTreePanel() != null ) {
364 getCurrentTreePanel().collapseSpeciesSpecificSubtrees();
367 else if ( o == _remove_branch_color_item ) {
368 if ( isSubtreeDisplayed() ) {
371 removeBranchColors();
373 else if ( o == _remove_visual_styles_item ) {
374 if ( isSubtreeDisplayed() ) {
377 removeVisualStyles();
379 else if ( o == _midpoint_root_item ) {
380 if ( isSubtreeDisplayed() ) {
385 else if ( o == _delete_selected_nodes_item ) {
386 if ( isSubtreeDisplayed() ) {
389 deleteSelectedNodes( true );
391 else if ( o == _delete_not_selected_nodes_item ) {
392 if ( isSubtreeDisplayed() ) {
395 deleteSelectedNodes( false );
397 else if ( o == _annotate_item ) {
400 else if ( o == _switch_colors_mi ) {
403 else if ( o == _display_basic_information_item ) {
404 if ( getCurrentTreePanel() != null ) {
405 displayBasicInformation( getCurrentTreePanel().getTreeFile() );
408 else if ( o == _view_as_NH_item ) {
411 else if ( o == _view_as_XML_item ) {
414 else if ( o == _view_as_nexus_item ) {
417 else if ( o == _super_tiny_fonts_item ) {
418 if ( getCurrentTreePanel() != null ) {
419 getCurrentTreePanel().setSuperTinyFonts();
420 getCurrentTreePanel().repaint();
423 else if ( o == _tiny_fonts_item ) {
424 if ( getCurrentTreePanel() != null ) {
425 getCurrentTreePanel().setTinyFonts();
426 getCurrentTreePanel().repaint();
429 else if ( o == _small_fonts_item ) {
430 if ( getCurrentTreePanel() != null ) {
431 getCurrentTreePanel().setSmallFonts();
432 getCurrentTreePanel().repaint();
435 else if ( o == _medium_fonts_item ) {
436 if ( getCurrentTreePanel() != null ) {
437 getCurrentTreePanel().setMediumFonts();
438 getCurrentTreePanel().repaint();
441 else if ( o == _large_fonts_item ) {
442 if ( getCurrentTreePanel() != null ) {
443 getCurrentTreePanel().setLargeFonts();
444 getCurrentTreePanel().repaint();
447 else if ( o == _choose_font_mi ) {
450 else if ( o == _choose_minimal_confidence_mi ) {
451 chooseMinimalConfidence();
453 else if ( o == _choose_node_size_mi ) {
454 chooseNodeSize( getOptions(), this );
456 else if ( o == _overview_placment_mi ) {
457 MainFrame.cycleOverview( getOptions(), getCurrentTreePanel() );
459 else if ( o == _cycle_node_fill_mi ) {
460 MainFrame.cycleNodeFill( getOptions() );
462 else if ( o == _cycle_node_shape_mi ) {
463 MainFrame.cycleNodeShape( getOptions() );
465 else if ( o == _cycle_data_return ) {
466 MainFrame.cycleNodeDataReturn( getOptions(), getConfiguration() );
468 else if ( o == _screen_antialias_cbmi ) {
469 updateOptions( getOptions() );
470 updateScreenTextAntialias( getMainPanel().getTreePanels() );
472 else if ( o == _background_gradient_cbmi ) {
473 updateOptions( getOptions() );
475 else if ( o == _show_domain_labels ) {
476 updateOptions( getOptions() );
478 else if ( o == _show_annotation_ref_source ) {
479 updateOptions( getOptions() );
481 else if ( o == _abbreviate_scientific_names ) {
482 updateOptions( getOptions() );
484 else if ( o == _color_labels_same_as_parent_branch ) {
485 updateOptions( getOptions() );
487 else if ( o == _show_default_node_shapes_internal_cbmi ) {
488 updateOptions( getOptions() );
490 else if ( o == _show_default_node_shapes_external_cbmi ) {
491 updateOptions( getOptions() );
493 else if ( o == _show_default_node_shapes_for_marked_cbmi ) {
494 updateOptions( getOptions() );
496 else if ( o == _non_lined_up_cladograms_rbmi ) {
497 updateOptions( getOptions() );
500 else if ( o == _uniform_cladograms_rbmi ) {
501 updateOptions( getOptions() );
504 else if ( o == _ext_node_dependent_cladogram_rbmi ) {
505 updateOptions( getOptions() );
508 else if ( o == _search_case_senstive_cbmi ) {
509 updateOptions( getOptions() );
510 getMainPanel().getControlPanel().search0();
511 getMainPanel().getControlPanel().search1();
513 else if ( o == _search_whole_words_only_cbmi ) {
514 if ( ( _search_with_regex_cbmi != null ) && _search_whole_words_only_cbmi.isSelected() ) {
515 _search_with_regex_cbmi.setSelected( false );
517 updateOptions( getOptions() );
518 getMainPanel().getControlPanel().search0();
519 getMainPanel().getControlPanel().search1();
521 else if ( o == _inverse_search_result_cbmi ) {
522 updateOptions( getOptions() );
523 getMainPanel().getControlPanel().search0();
524 getMainPanel().getControlPanel().search1();
526 else if ( o == _search_with_regex_cbmi ) {
527 if ( ( _search_whole_words_only_cbmi != null ) && _search_with_regex_cbmi.isSelected() ) {
528 _search_whole_words_only_cbmi.setSelected( false );
530 if ( ( _search_case_senstive_cbmi != null ) && _search_with_regex_cbmi.isSelected() ) {
531 _search_case_senstive_cbmi.setSelected( true );
533 updateOptions( getOptions() );
534 getMainPanel().getControlPanel().search0();
535 getMainPanel().getControlPanel().search1();
537 else if ( o == _color_all_found_nodes_when_coloring_subtree_cbmi ) {
538 updateOptions( getOptions() );
540 else if ( o == _parse_beast_style_extended_nexus_tags_cbmi ) {
541 updateOptions( getOptions() );
543 else if ( o == _show_scale_cbmi ) {
544 updateOptions( getOptions() );
546 else if ( o == _color_by_taxonomic_group_cbmi ) {
547 updateOptions( getOptions() );
549 else if ( o == _show_confidence_stddev_cbmi ) {
550 updateOptions( getOptions() );
552 else if ( o == _use_brackets_for_conf_in_nh_export_cbmi ) {
553 if ( _use_brackets_for_conf_in_nh_export_cbmi.isSelected() ) {
554 _use_internal_names_for_conf_in_nh_export_cbmi.setSelected( false );
556 updateOptions( getOptions() );
558 else if ( o == _use_internal_names_for_conf_in_nh_export_cbmi ) {
559 if ( _use_internal_names_for_conf_in_nh_export_cbmi.isSelected() ) {
560 _use_brackets_for_conf_in_nh_export_cbmi.setSelected( false );
562 updateOptions( getOptions() );
564 else if ( o == _label_direction_cbmi ) {
565 updateOptions( getOptions() );
567 else if ( o == _show_overview_cbmi ) {
568 updateOptions( getOptions() );
569 if ( getCurrentTreePanel() != null ) {
570 getCurrentTreePanel().updateOvSizes();
573 else if ( o == _line_up_renderable_data_cbmi ) {
574 if ( !_line_up_renderable_data_cbmi.isSelected() ) {
575 _right_line_up_domains_cbmi.setSelected( false );
577 updateOptions( getOptions() );
579 else if ( o == _right_line_up_domains_cbmi ) {
580 if ( _right_line_up_domains_cbmi.isSelected() ) {
581 _line_up_renderable_data_cbmi.setSelected( true );
583 updateOptions( getOptions() );
585 else if ( ( o == _rectangular_type_cbmi ) || ( o == _triangular_type_cbmi ) || ( o == _curved_type_cbmi )
586 || ( o == _convex_type_cbmi ) || ( o == _euro_type_cbmi ) || ( o == _rounded_type_cbmi )
587 || ( o == _unrooted_type_cbmi ) || ( o == _circular_type_cbmi ) ) {
590 else if ( o == _about_item ) {
593 else if ( o == _help_item ) {
595 AptxUtil.openWebsite( AptxConstants.APTX_DOC_SITE, is_applet, applet );
597 catch ( final IOException e1 ) {
598 ForesterUtil.printErrorMessage( AptxConstants.PRG_NAME, e1.toString() );
601 else if ( o == _website_item ) {
603 AptxUtil.openWebsite( AptxConstants.APTX_WEB_SITE, is_applet, applet );
605 catch ( final IOException e1 ) {
606 ForesterUtil.printErrorMessage( AptxConstants.PRG_NAME, e1.toString() );
609 else if ( o == _phyloxml_website_item ) {
611 AptxUtil.openWebsite( AptxConstants.PHYLOXML_WEB_SITE, is_applet, applet );
613 catch ( final IOException e1 ) {
614 ForesterUtil.printErrorMessage( AptxConstants.PRG_NAME, e1.toString() );
617 else if ( o == _aptx_ref_item ) {
619 AptxUtil.openWebsite( AptxConstants.APTX_REFERENCE_URL, is_applet, applet );
621 catch ( final IOException e1 ) {
622 ForesterUtil.printErrorMessage( AptxConstants.PRG_NAME, e1.toString() );
625 else if ( o == _phyloxml_ref_item ) {
627 AptxUtil.openWebsite( AptxConstants.PHYLOXML_REFERENCE_URL, is_applet, applet );
629 catch ( final IOException e1 ) {
630 ForesterUtil.printErrorMessage( AptxConstants.PRG_NAME, e1.toString() );
633 else if ( o == _write_to_pdf_item ) {
634 final File curr_dir = writeToPdf( _mainpanel.getCurrentPhylogeny(),
636 _writetopdf_filechooser,
640 if ( curr_dir != null ) {
641 setCurrentDir( curr_dir );
644 else if ( o == _save_all_item ) {
647 else if ( o == _write_to_jpg_item ) {
648 final File new_dir = writeToGraphicsFile( _mainpanel.getCurrentPhylogeny(),
649 GraphicsExportType.JPG,
651 _writetographics_filechooser,
655 if ( new_dir != null ) {
656 setCurrentDir( new_dir );
659 else if ( o == _write_to_gif_item ) {
660 final File new_dir = writeToGraphicsFile( _mainpanel.getCurrentPhylogeny(),
661 GraphicsExportType.GIF,
663 _writetographics_filechooser,
667 if ( new_dir != null ) {
668 setCurrentDir( new_dir );
671 else if ( o == _write_to_tif_item ) {
672 final File new_dir = writeToGraphicsFile( _mainpanel.getCurrentPhylogeny(),
673 GraphicsExportType.TIFF,
675 _writetographics_filechooser,
679 if ( new_dir != null ) {
680 setCurrentDir( new_dir );
683 else if ( o == _write_to_bmp_item ) {
684 final File new_dir = writeToGraphicsFile( _mainpanel.getCurrentPhylogeny(),
685 GraphicsExportType.BMP,
687 _writetographics_filechooser,
691 if ( new_dir != null ) {
692 setCurrentDir( new_dir );
695 else if ( o == _write_to_png_item ) {
696 final File new_dir = writeToGraphicsFile( _mainpanel.getCurrentPhylogeny(),
697 GraphicsExportType.PNG,
699 _writetographics_filechooser,
703 if ( new_dir != null ) {
704 setCurrentDir( new_dir );
707 else if ( o == _print_item ) {
708 print( getCurrentTreePanel(), getOptions(), this );
710 else if ( o == _save_item ) {
711 final File new_dir = writeToFile( _mainpanel.getCurrentPhylogeny(),
717 if ( new_dir != null ) {
718 setCurrentDir( new_dir );
721 else if ( o == _graphics_export_visible_only_cbmi ) {
722 updateOptions( getOptions() );
724 else if ( o == _antialias_print_cbmi ) {
725 updateOptions( getOptions() );
727 else if ( o == _print_black_and_white_cbmi ) {
728 updateOptions( getOptions() );
730 else if ( o == _choose_pdf_width_mi ) {
733 else if ( o == _lineage_inference ) {
734 if ( isSubtreeDisplayed() ) {
735 JOptionPane.showMessageDialog( this,
737 "Cannot infer ancestral taxonomies",
738 JOptionPane.ERROR_MESSAGE );
741 executeLineageInference();
744 if ( _load_phylogeny_from_webservice_menu_items != null ) {
745 for( int i = 0; i < _load_phylogeny_from_webservice_menu_items.length; ++i ) {
746 if ( o == _load_phylogeny_from_webservice_menu_items[ i ] ) {
747 readPhylogeniesFromWebservice( i );
752 _contentpane.repaint();
755 public Configuration getConfiguration() {
756 return _configuration;
760 * This method returns the current external node data which
761 * has been selected by the user by clicking the "Return ..."
762 * menu item. This method is expected to be called from Javascript or
765 * @return current external node data as String
767 public String getCurrentExternalNodesDataBuffer() {
768 return getCurrentTreePanel().getCurrentExternalNodesDataBufferAsString();
771 public int getCurrentExternalNodesDataBufferChangeCounter() {
772 return getCurrentTreePanel().getCurrentExternalNodesDataBufferChangeCounter();
775 public int getCurrentExternalNodesDataBufferLength() {
776 return getCurrentTreePanel().getCurrentExternalNodesDataBufferAsString().length();
779 public InferenceManager getInferenceManager() {
780 return _inference_manager;
783 public MainPanel getMainPanel() {
787 public Options getOptions() {
791 public ProcessPool getProcessPool() {
792 return _process_pool;
795 public void showTextFrame( final String s, final String title ) {
797 _textframes.addLast( TextFrame.instantiate( s, title, _textframes ) );
800 public void showWhole() {
801 _mainpanel.getControlPanel().showWhole();
804 public void updateProcessMenu() {
805 // In general Swing is not thread safe.
806 // See "Swing's Threading Policy".
807 SwingUtilities.invokeLater( new Runnable() {
811 doUpdateProcessMenu();
816 private void annotateSequences() {
817 if ( getCurrentTreePanel() != null ) {
818 List<PhylogenyNode> nodes = null;
819 if ( ( getCurrentTreePanel().getFoundNodes0() != null )
820 || ( getCurrentTreePanel().getFoundNodes1() != null ) ) {
821 nodes = getCurrentTreePanel().getFoundNodesAsListOfPhylogenyNodes();
823 if ( ( nodes == null ) || nodes.isEmpty() ) {
825 .showMessageDialog( this,
826 "Need to select nodes, either via direct selection or via the \"Search\" function",
827 "No nodes selected for annotation",
828 JOptionPane.ERROR_MESSAGE );
831 final Phylogeny phy = getMainPanel().getCurrentPhylogeny();
832 if ( ( phy != null ) && !phy.isEmpty() ) {
833 final JTextField ref_field = new JTextField( 10 );
834 final JTextField desc_filed = new JTextField( 20 );
835 ref_field.setText( ForesterUtil.isEmpty( getPreviousNodeAnnotationReference() ) ? ""
836 : getPreviousNodeAnnotationReference() );
837 final JPanel my_panel = new JPanel();
838 my_panel.add( new JLabel( "Reference " ) );
839 my_panel.add( ref_field );
840 my_panel.add( Box.createHorizontalStrut( 15 ) );
841 my_panel.add( new JLabel( "Description " ) );
842 my_panel.add( desc_filed );
843 final int result = JOptionPane.showConfirmDialog( null,
845 "Enter the sequence annotation(s) for the "
846 + nodes.size() + " selected nodes",
847 JOptionPane.OK_CANCEL_OPTION );
848 if ( result == JOptionPane.OK_OPTION ) {
849 String ref = ref_field.getText();
850 String desc = desc_filed.getText();
851 if ( !ForesterUtil.isEmpty( ref ) ) {
853 ref = ref.replaceAll( "\\s+", " " );
854 if ( ( ref.indexOf( ':' ) < 1 ) || ( ref.indexOf( ':' ) > ( ref.length() - 2 ) )
855 || ( ref.length() < 3 ) ) {
856 JOptionPane.showMessageDialog( this,
857 "Reference needs to be in the form of \"GO:1234567\"",
858 "Illegal Format for Annotation Reference",
859 JOptionPane.ERROR_MESSAGE );
864 setPreviousNodeAnnotationReference( ref );
866 if ( desc != null ) {
868 desc = desc.replaceAll( "\\s+", " " );
870 if ( !ForesterUtil.isEmpty( ref ) || !ForesterUtil.isEmpty( desc ) ) {
871 for( final PhylogenyNode n : nodes ) {
872 ForesterUtil.ensurePresenceOfSequence( n );
873 final Annotation ann = ForesterUtil.isEmpty( ref ) ? new Annotation()
874 : new Annotation( ref );
875 if ( !ForesterUtil.isEmpty( desc ) ) {
878 n.getNodeData().getSequence().addAnnotation( ann );
881 getMainPanel().getControlPanel().showAnnotations();
887 private void chooseFont() {
888 final FontChooser fc = new FontChooser();
889 fc.setFont( getMainPanel().getTreeFontSet().getLargeFont() );
890 fc.showDialog( this, "Select the Base Font" );
891 getMainPanel().getTreeFontSet().setBaseFont( fc.getFont() );
892 getControlPanel().displayedPhylogenyMightHaveChanged( true );
893 getMainPanel().getCurrentTreePanel().resetPreferredSize();
894 getMainPanel().getCurrentTreePanel().updateOvSizes();
899 private void chooseMinimalConfidence() {
900 final String s = ( String ) JOptionPane
901 .showInputDialog( this,
902 "Please enter the minimum for confidence values to be displayed.\n"
903 + "[current value: " + getOptions().getMinConfidenceValue() + "]\n",
904 "Minimal Confidence Value",
905 JOptionPane.QUESTION_MESSAGE,
908 getOptions().getMinConfidenceValue() );
909 if ( !ForesterUtil.isEmpty( s ) ) {
910 boolean success = true;
912 final String m_str = s.trim();
913 if ( !ForesterUtil.isEmpty( m_str ) ) {
915 m = Double.parseDouble( m_str );
917 catch ( final Exception ex ) {
924 if ( success && ( m >= 0.0 ) ) {
925 getOptions().setMinConfidenceValue( m );
930 private void deleteSelectedNodes( final boolean delete ) {
931 final Phylogeny phy = getMainPanel().getCurrentPhylogeny();
932 if ( ( phy == null ) || ( phy.getNumberOfExternalNodes() < 2 ) ) {
935 final List<PhylogenyNode> nodes = new ArrayList<PhylogenyNode>();
936 if ( ( getCurrentTreePanel().getFoundNodes0() != null ) || ( getCurrentTreePanel().getFoundNodes1() != null ) ) {
937 final List<PhylogenyNode> all_selected_nodes = getCurrentTreePanel().getFoundNodesAsListOfPhylogenyNodes();
938 for( final PhylogenyNode n : all_selected_nodes ) {
939 if ( n.isExternal() ) {
944 String function = "Retain";
948 if ( ( nodes == null ) || nodes.isEmpty() ) {
950 .showMessageDialog( this,
951 "Need to select external nodes, either via direct selection or via the \"Search\" function",
952 "No external nodes selected to " + function.toLowerCase(),
953 JOptionPane.ERROR_MESSAGE );
956 final int todo = nodes.size();
957 final int ext = phy.getNumberOfExternalNodes();
963 JOptionPane.showMessageDialog( this,
964 "Cannot delete all nodes",
965 "Attempt to delete all nodes ",
966 JOptionPane.ERROR_MESSAGE );
969 final int result = JOptionPane.showConfirmDialog( null, function + " " + todo
970 + " external node(s), from a total of " + ext + " external nodes," + "\nresulting in tree with " + res
971 + " nodes?", function + " external nodes", JOptionPane.OK_CANCEL_OPTION );
972 if ( result == JOptionPane.OK_OPTION ) {
974 final List<PhylogenyNode> to_delete = new ArrayList<PhylogenyNode>();
975 for( final PhylogenyNodeIterator it = phy.iteratorExternalForward(); it.hasNext(); ) {
976 final PhylogenyNode n = it.next();
977 if ( !nodes.contains( n ) ) {
981 for( final PhylogenyNode n : to_delete ) {
982 phy.deleteSubtree( n, true );
986 for( final PhylogenyNode n : nodes ) {
987 phy.deleteSubtree( n, true );
991 getCurrentTreePanel().setNodeInPreorderToNull();
992 phy.externalNodesHaveChanged();
993 phy.clearHashIdToNodeMap();
994 phy.recalculateNumberOfExternalDescendants( true );
995 getCurrentTreePanel().resetNodeIdToDistToLeafMap();
996 getCurrentTreePanel().setEdited( true );
1001 private void doUpdateProcessMenu() {
1002 if ( _process_pool.size() > 0 ) {
1003 if ( _process_menu == null ) {
1004 _process_menu = createMenu( "", getConfiguration() );
1005 _process_menu.setForeground( Color.RED );
1007 _process_menu.removeAll();
1008 final String text = "processes running: " + _process_pool.size();
1009 _process_menu.setText( text );
1010 _jmenubar.add( _process_menu );
1011 for( int i = 0; i < _process_pool.size(); ++i ) {
1012 final ProcessRunning p = _process_pool.getProcessByIndex( i );
1013 _process_menu.add( customizeJMenuItem( new JMenuItem( p.getName() + " [" + p.getStart() + "]" ) ) );
1017 if ( _process_menu != null ) {
1018 _process_menu.removeAll();
1019 _jmenubar.remove( _process_menu );
1022 _jmenubar.validate();
1023 _jmenubar.repaint();
1027 private String getPreviousNodeAnnotationReference() {
1028 return _previous_node_annotation_ref;
1031 private void removeBranchColors() {
1032 if ( getMainPanel().getCurrentPhylogeny() != null ) {
1033 AptxUtil.removeBranchColors( getMainPanel().getCurrentPhylogeny() );
1037 private void removeVisualStyles() {
1038 if ( getMainPanel().getCurrentPhylogeny() != null ) {
1039 AptxUtil.removeVisualStyles( getMainPanel().getCurrentPhylogeny() );
1043 private void setPreviousNodeAnnotationReference( final String previous_node_annotation_ref ) {
1044 _previous_node_annotation_ref = previous_node_annotation_ref;
1047 private void writeAllToFile() {
1048 if ( ( getMainPanel().getTabbedPane() == null ) || ( getMainPanel().getTabbedPane().getTabCount() < 1 ) ) {
1051 final File my_dir = getCurrentDir();
1052 if ( my_dir != null ) {
1053 _save_filechooser.setCurrentDirectory( my_dir );
1055 _save_filechooser.setSelectedFile( new File( "" ) );
1056 final int result = _save_filechooser.showSaveDialog( _contentpane );
1057 final File file = _save_filechooser.getSelectedFile();
1058 setCurrentDir( _save_filechooser.getCurrentDirectory() );
1059 if ( ( file != null ) && ( result == JFileChooser.APPROVE_OPTION ) ) {
1060 if ( file.exists() ) {
1061 final int i = JOptionPane.showConfirmDialog( this,
1062 file + " already exists. Overwrite?",
1064 JOptionPane.OK_CANCEL_OPTION,
1065 JOptionPane.WARNING_MESSAGE );
1066 if ( i != JOptionPane.OK_OPTION ) {
1073 catch ( final Exception e ) {
1074 JOptionPane.showMessageDialog( this,
1075 "Failed to delete: " + file,
1077 JOptionPane.WARNING_MESSAGE );
1081 final int count = getMainPanel().getTabbedPane().getTabCount();
1082 final List<Phylogeny> trees = new ArrayList<Phylogeny>();
1083 for( int i = 0; i < count; ++i ) {
1084 final Phylogeny phy = getMainPanel().getPhylogeny( i );
1085 if ( ForesterUtil.isEmpty( phy.getName() )
1086 && !ForesterUtil.isEmpty( getMainPanel().getTabbedPane().getTitleAt( i ) ) ) {
1087 phy.setName( getMainPanel().getTabbedPane().getTitleAt( i ) );
1090 getMainPanel().getTreePanels().get( i ).setEdited( false );
1092 final PhylogenyWriter writer = new PhylogenyWriter();
1094 writer.toPhyloXML( file, trees, 0, ForesterUtil.LINE_SEPARATOR );
1096 catch ( final IOException e ) {
1097 JOptionPane.showMessageDialog( this,
1098 "Failed to write to: " + file,
1100 JOptionPane.WARNING_MESSAGE );
1105 void activateSaveAllIfNeeded() {
1106 if ( ( getMainPanel().getTabbedPane() != null ) && ( getMainPanel().getTabbedPane().getTabCount() > 1 ) ) {
1107 _save_all_item.setEnabled( true );
1110 _save_all_item.setEnabled( false );
1114 void buildFileMenu() {
1115 _file_jmenu = MainFrame.createMenu( "File", getConfiguration() );
1116 _file_jmenu.add( _save_item = new JMenuItem( "Save Tree As..." ) );
1117 _file_jmenu.addSeparator();
1118 _file_jmenu.add( _write_to_pdf_item = new JMenuItem( "Export to PDF file ..." ) );
1119 if ( AptxUtil.canWriteFormat( "tif" ) || AptxUtil.canWriteFormat( "tiff" ) || AptxUtil.canWriteFormat( "TIF" ) ) {
1120 _file_jmenu.add( _write_to_tif_item = new JMenuItem( "Export to TIFF file..." ) );
1122 _file_jmenu.add( _write_to_png_item = new JMenuItem( "Export to PNG file..." ) );
1123 _file_jmenu.add( _write_to_jpg_item = new JMenuItem( "Export to JPG file..." ) );
1124 if ( AptxUtil.canWriteFormat( "gif" ) ) {
1125 _file_jmenu.add( _write_to_gif_item = new JMenuItem( "Export to GIF file..." ) );
1127 if ( AptxUtil.canWriteFormat( "bmp" ) ) {
1128 _file_jmenu.add( _write_to_bmp_item = new JMenuItem( "Export to BMP file..." ) );
1130 _file_jmenu.addSeparator();
1131 _file_jmenu.add( _print_item = new JMenuItem( "Print..." ) );
1132 _file_jmenu.addSeparator();
1133 _file_jmenu.add( _exit_item = new JMenuItem( "Exit" ) );
1134 customizeJMenuItem( _save_item );
1135 customizeJMenuItem( _write_to_pdf_item );
1136 customizeJMenuItem( _write_to_png_item );
1137 customizeJMenuItem( _write_to_jpg_item );
1138 customizeJMenuItem( _write_to_gif_item );
1139 customizeJMenuItem( _write_to_tif_item );
1140 customizeJMenuItem( _write_to_bmp_item );
1141 customizeJMenuItem( _print_item );
1142 customizeJMenuItem( _exit_item );
1143 _jmenubar.add( _file_jmenu );
1146 void buildFontSizeMenu() {
1147 _font_size_menu = createMenu( FONT_SIZE_MENU_LABEL, getConfiguration() );
1148 _font_size_menu.add( _super_tiny_fonts_item = new JMenuItem( "Super Tiny Fonts" ) );
1149 _font_size_menu.add( _tiny_fonts_item = new JMenuItem( "Tiny Fonts" ) );
1150 _font_size_menu.add( _small_fonts_item = new JMenuItem( "Small Fonts" ) );
1151 _font_size_menu.add( _medium_fonts_item = new JMenuItem( "Medium Fonts" ) );
1152 _font_size_menu.add( _large_fonts_item = new JMenuItem( "Large Fonts" ) );
1153 customizeJMenuItem( _super_tiny_fonts_item );
1154 customizeJMenuItem( _tiny_fonts_item );
1155 customizeJMenuItem( _small_fonts_item );
1156 customizeJMenuItem( _medium_fonts_item );
1157 customizeJMenuItem( _large_fonts_item );
1158 _jmenubar.add( _font_size_menu );
1161 void buildHelpMenu() {
1162 _help_jmenu = createMenu( "Help", getConfiguration() );
1163 _help_jmenu.add( _help_item = new JMenuItem( "Documentation" ) );
1164 _help_jmenu.addSeparator();
1165 _help_jmenu.add( _website_item = new JMenuItem( "Archaeopteryx Home" ) );
1166 _aptx_ref_item = new JMenuItem( "Archaeopteryx Reference" ); //TODO need to add this...
1167 _help_jmenu.add( _phyloxml_website_item = new JMenuItem( "phyloXML Home" ) );
1168 _help_jmenu.add( _phyloxml_ref_item = new JMenuItem( "phyloXML Reference" ) );
1169 _help_jmenu.addSeparator();
1170 _help_jmenu.add( _about_item = new JMenuItem( "About" ) );
1171 customizeJMenuItem( _help_item );
1172 customizeJMenuItem( _website_item );
1173 customizeJMenuItem( _phyloxml_website_item );
1174 customizeJMenuItem( _aptx_ref_item );
1175 customizeJMenuItem( _phyloxml_ref_item );
1176 customizeJMenuItem( _about_item );
1177 _phyloxml_ref_item.setToolTipText( PHYLOXML_REF_TOOL_TIP );
1178 _aptx_ref_item.setToolTipText( APTX_REF_TOOL_TIP );
1179 _jmenubar.add( _help_jmenu );
1182 void buildTypeMenu() {
1183 _type_menu = createMenu( TYPE_MENU_HEADER, getConfiguration() );
1184 _type_menu.add( _rectangular_type_cbmi = new JCheckBoxMenuItem( MainFrame.RECTANGULAR_TYPE_CBMI_LABEL ) );
1185 _type_menu.add( _euro_type_cbmi = new JCheckBoxMenuItem( MainFrame.EURO_TYPE_CBMI_LABEL ) );
1186 _type_menu.add( _rounded_type_cbmi = new JCheckBoxMenuItem( MainFrame.ROUNDED_TYPE_CBMI_LABEL ) );
1187 _type_menu.add( _curved_type_cbmi = new JCheckBoxMenuItem( MainFrame.CURVED_TYPE_CBMI_LABEL ) );
1188 _type_menu.add( _triangular_type_cbmi = new JCheckBoxMenuItem( MainFrame.TRIANGULAR_TYPE_CBMI_LABEL ) );
1189 _type_menu.add( _convex_type_cbmi = new JCheckBoxMenuItem( MainFrame.CONVEX_TYPE_CBMI_LABEL ) );
1190 _type_menu.add( _unrooted_type_cbmi = new JCheckBoxMenuItem( MainFrame.UNROOTED_TYPE_CBMI_LABEL ) );
1191 _type_menu.add( _circular_type_cbmi = new JCheckBoxMenuItem( MainFrame.CIRCULAR_TYPE_CBMI_LABEL ) );
1192 customizeCheckBoxMenuItem( _rectangular_type_cbmi, false );
1193 customizeCheckBoxMenuItem( _triangular_type_cbmi, false );
1194 customizeCheckBoxMenuItem( _euro_type_cbmi, false );
1195 customizeCheckBoxMenuItem( _rounded_type_cbmi, false );
1196 customizeCheckBoxMenuItem( _curved_type_cbmi, false );
1197 customizeCheckBoxMenuItem( _convex_type_cbmi, false );
1198 customizeCheckBoxMenuItem( _unrooted_type_cbmi, false );
1199 customizeCheckBoxMenuItem( _circular_type_cbmi, false );
1200 _unrooted_type_cbmi.setToolTipText( MainFrame.USE_MOUSEWHEEL_SHIFT_TO_ROTATE );
1201 _circular_type_cbmi.setToolTipText( MainFrame.USE_MOUSEWHEEL_SHIFT_TO_ROTATE );
1202 initializeTypeMenu( getOptions() );
1203 _jmenubar.add( _type_menu );
1206 void buildViewMenu() {
1207 _view_jmenu = createMenu( "View", getConfiguration() );
1208 _view_jmenu.add( _display_basic_information_item = new JMenuItem( SHOW_BASIC_TREE_INFORMATION_LABEL ) );
1209 _view_jmenu.addSeparator();
1210 _view_jmenu.add( _view_as_XML_item = new JMenuItem( "as phyloXML" ) );
1211 _view_jmenu.add( _view_as_NH_item = new JMenuItem( "as Newick" ) );
1212 _view_jmenu.add( _view_as_nexus_item = new JMenuItem( "as Nexus" ) );
1213 customizeJMenuItem( _display_basic_information_item );
1214 customizeJMenuItem( _view_as_NH_item );
1215 customizeJMenuItem( _view_as_XML_item );
1216 customizeJMenuItem( _view_as_nexus_item );
1217 _jmenubar.add( _view_jmenu );
1220 void checkTextFrames() {
1221 if ( _textframes.size() > 5 ) {
1223 if ( _textframes.getFirst() != null ) {
1224 _textframes.getFirst().removeMe();
1227 _textframes.removeFirst();
1230 catch ( final NoSuchElementException e ) {
1236 void choosePdfWidth() {
1237 final String s = ( String ) JOptionPane.showInputDialog( this,
1238 "Please enter the default line width for PDF export.\n"
1239 + "[current value: "
1240 + getOptions().getPrintLineWidth() + "]\n",
1241 "Line Width for PDF Export",
1242 JOptionPane.QUESTION_MESSAGE,
1245 getOptions().getPrintLineWidth() );
1246 if ( !ForesterUtil.isEmpty( s ) ) {
1247 boolean success = true;
1249 final String m_str = s.trim();
1250 if ( !ForesterUtil.isEmpty( m_str ) ) {
1252 f = Float.parseFloat( m_str );
1254 catch ( final Exception ex ) {
1261 if ( success && ( f > 0.0 ) ) {
1262 getOptions().setPrintLineWidth( f );
1268 removeAllTextFrames();
1269 if ( _mainpanel != null ) {
1270 _mainpanel.terminate();
1272 if ( _contentpane != null ) {
1273 _contentpane.removeAll();
1275 setVisible( false );
1280 if ( _mainpanel.getCurrentTreePanel() != null ) {
1281 final String[] ranks = AptxUtil.getAllPossibleRanks();
1282 final String rank = ( String ) JOptionPane
1283 .showInputDialog( this,
1284 "What rank should the colorization be based on",
1286 JOptionPane.QUESTION_MESSAGE,
1290 if ( !ForesterUtil.isEmpty( rank ) ) {
1291 _mainpanel.getCurrentTreePanel().colorRank( rank );
1297 if ( _mainpanel.getCurrentTreePanel() != null ) {
1298 _mainpanel.getCurrentTreePanel().confColor();
1302 void customizeCheckBoxMenuItem( final JCheckBoxMenuItem item, final boolean is_selected ) {
1303 if ( item != null ) {
1304 item.setFont( MainFrame.menu_font );
1305 if ( !getConfiguration().isUseNativeUI() ) {
1306 item.setBackground( getConfiguration().getGuiMenuBackgroundColor() );
1307 item.setForeground( getConfiguration().getGuiMenuTextColor() );
1309 item.setSelected( is_selected );
1310 item.addActionListener( this );
1314 JMenuItem customizeJMenuItem( final JMenuItem jmi ) {
1315 if ( jmi != null ) {
1316 jmi.setFont( MainFrame.menu_font );
1317 if ( !getConfiguration().isUseNativeUI() ) {
1318 jmi.setBackground( getConfiguration().getGuiMenuBackgroundColor() );
1319 jmi.setForeground( getConfiguration().getGuiMenuTextColor() );
1321 jmi.addActionListener( this );
1326 void customizeRadioButtonMenuItem( final JRadioButtonMenuItem item, final boolean is_selected ) {
1327 if ( item != null ) {
1328 item.setFont( MainFrame.menu_font );
1329 if ( !getConfiguration().isUseNativeUI() ) {
1330 item.setBackground( getConfiguration().getGuiMenuBackgroundColor() );
1331 item.setForeground( getConfiguration().getGuiMenuTextColor() );
1333 item.setSelected( is_selected );
1334 item.addActionListener( this );
1338 void displayBasicInformation( final File treefile ) {
1339 if ( ( _mainpanel.getCurrentPhylogeny() != null ) && !_mainpanel.getCurrentPhylogeny().isEmpty() ) {
1340 String title = "Basic Information";
1341 if ( !ForesterUtil.isEmpty( _mainpanel.getCurrentPhylogeny().getName() ) ) {
1342 title = title + " for \"" + _mainpanel.getCurrentPhylogeny().getName() + "\"";
1344 showTextFrame( AptxUtil.createBasicInformation( _mainpanel.getCurrentPhylogeny(), treefile ), title );
1348 void exceptionOccuredDuringOpenFile( final Exception e ) {
1350 _mainpanel.getCurrentTreePanel().setArrowCursor();
1352 catch ( final Exception ex ) {
1355 JOptionPane.showMessageDialog( this,
1356 ForesterUtil.wordWrap( e.getLocalizedMessage(), 80 ),
1357 "Error during File|Open",
1358 JOptionPane.ERROR_MESSAGE );
1361 void executeGSDI() {
1362 if ( !isOKforSDI( false, true ) ) {
1365 if ( !_mainpanel.getCurrentPhylogeny().isRooted() ) {
1366 JOptionPane.showMessageDialog( this,
1367 "Gene tree is not rooted.",
1368 "Cannot execute GSDI",
1369 JOptionPane.ERROR_MESSAGE );
1372 final Phylogeny gene_tree = _mainpanel.getCurrentPhylogeny().copy();
1373 gene_tree.setAllNodesToNotCollapse();
1374 gene_tree.recalculateNumberOfExternalDescendants( false );
1376 final Phylogeny species_tree = getSpeciesTree().copy();
1378 gsdi = new GSDI( gene_tree, species_tree, false, true, true, true );
1380 catch ( final SDIException e ) {
1381 JOptionPane.showMessageDialog( this,
1382 e.getLocalizedMessage(),
1383 "Error during GSDI",
1384 JOptionPane.ERROR_MESSAGE );
1387 catch ( final Exception e ) {
1388 AptxUtil.unexpectedException( e );
1391 gene_tree.setRerootable( false );
1392 gene_tree.clearHashIdToNodeMap();
1393 gene_tree.recalculateNumberOfExternalDescendants( true );
1394 _mainpanel.addPhylogenyInNewTab( gene_tree, getConfiguration(), "gene tree", null );
1395 getMainPanel().getControlPanel().setShowEvents( true );
1397 final int selected = _mainpanel.getTabbedPane().getSelectedIndex();
1398 _mainpanel.addPhylogenyInNewTab( species_tree, getConfiguration(), "species tree", null );
1400 _mainpanel.getTabbedPane().setSelectedIndex( selected );
1402 _mainpanel.getCurrentTreePanel().setEdited( true );
1403 final int poly = PhylogenyMethods.countNumberOfPolytomies( species_tree );
1404 if ( gsdi.getStrippedExternalGeneTreeNodes().size() > 0 ) {
1405 JOptionPane.showMessageDialog( this,
1406 "Duplications: " + gsdi.getDuplicationsSum() + "\n"
1407 + "Potential duplications: "
1408 + gsdi.getSpeciationOrDuplicationEventsSum() + "\n"
1409 + "Speciations: " + gsdi.getSpeciationsSum() + "\n"
1410 + "Stripped gene tree nodes: "
1411 + gsdi.getStrippedExternalGeneTreeNodes().size() + "\n"
1412 + "Taxonomy linkage based on: " + gsdi.getTaxCompBase() + "\n"
1413 + "Number of polytomies in species tree used: " + poly + "\n",
1414 "GSDI successfully completed",
1415 JOptionPane.WARNING_MESSAGE );
1418 JOptionPane.showMessageDialog( this,
1419 "Duplications: " + gsdi.getDuplicationsSum() + "\n"
1420 + "Potential duplications: "
1421 + gsdi.getSpeciationOrDuplicationEventsSum() + "\n"
1422 + "Speciations: " + gsdi.getSpeciationsSum() + "\n"
1423 + "Stripped gene tree nodes: "
1424 + gsdi.getStrippedExternalGeneTreeNodes().size() + "\n"
1425 + "Taxonomy linkage based on: " + gsdi.getTaxCompBase() + "\n"
1426 + "Number of polytomies in species tree used: " + poly + "\n",
1427 "GSDI successfully completed",
1428 JOptionPane.INFORMATION_MESSAGE );
1432 void executeGSDIR() {
1433 if ( !isOKforSDI( false, false ) ) {
1436 final int p = PhylogenyMethods.countNumberOfPolytomies( _mainpanel.getCurrentPhylogeny() );
1438 && !( ( p == 1 ) && ( _mainpanel.getCurrentPhylogeny().getRoot().getNumberOfDescendants() == 3 ) ) ) {
1439 JOptionPane.showMessageDialog( this,
1440 "Gene tree is not completely binary",
1441 "Cannot execute GSDI",
1442 JOptionPane.ERROR_MESSAGE );
1445 final Phylogeny gene_tree = _mainpanel.getCurrentPhylogeny().copy();
1446 gene_tree.setAllNodesToNotCollapse();
1447 gene_tree.recalculateNumberOfExternalDescendants( false );
1449 final Phylogeny species_tree = getSpeciesTree().copy();
1451 gsdir = new GSDIR( gene_tree, species_tree, true, true, true );
1453 catch ( final SDIException e ) {
1454 JOptionPane.showMessageDialog( this,
1455 e.getLocalizedMessage(),
1456 "Error during GSDIR",
1457 JOptionPane.ERROR_MESSAGE );
1460 catch ( final Exception e ) {
1461 AptxUtil.unexpectedException( e );
1464 final Phylogeny result_gene_tree = gsdir.getMinDuplicationsSumGeneTree();
1465 result_gene_tree.setRerootable( false );
1466 result_gene_tree.clearHashIdToNodeMap();
1467 result_gene_tree.recalculateNumberOfExternalDescendants( true );
1468 PhylogenyMethods.orderAppearance( result_gene_tree.getRoot(), true, true, DESCENDANT_SORT_PRIORITY.NODE_NAME );
1469 _mainpanel.addPhylogenyInNewTab( result_gene_tree, getConfiguration(), "gene tree", null );
1470 getMainPanel().getControlPanel().setShowEvents( true );
1472 final int selected = _mainpanel.getTabbedPane().getSelectedIndex();
1473 _mainpanel.addPhylogenyInNewTab( species_tree, getConfiguration(), "species tree", null );
1475 _mainpanel.getTabbedPane().setSelectedIndex( selected );
1477 _mainpanel.getCurrentTreePanel().setEdited( true );
1478 final int poly = PhylogenyMethods.countNumberOfPolytomies( species_tree );
1479 if ( gsdir.getStrippedExternalGeneTreeNodes().size() > 0 ) {
1480 JOptionPane.showMessageDialog( this,
1481 "Minimal duplications: " + gsdir.getMinDuplicationsSum() + "\n"
1482 + "Speciations: " + gsdir.getSpeciationsSum() + "\n"
1483 + "Stripped gene tree nodes: "
1484 + gsdir.getStrippedExternalGeneTreeNodes().size() + "\n"
1485 + "Taxonomy linkage based on: " + gsdir.getTaxCompBase() + "\n"
1486 + "Number of polytomies in species tree used: " + poly + "\n",
1487 "GSDIR successfully completed",
1488 JOptionPane.WARNING_MESSAGE );
1491 JOptionPane.showMessageDialog( this,
1492 "Minimal duplications: " + gsdir.getMinDuplicationsSum() + "\n"
1493 + "Speciations: " + gsdir.getSpeciationsSum() + "\n"
1494 + "Stripped gene tree nodes: "
1495 + gsdir.getStrippedExternalGeneTreeNodes().size() + "\n"
1496 + "Taxonomy linkage based on: " + gsdir.getTaxCompBase() + "\n"
1497 + "Number of polytomies in species tree used: " + poly + "\n",
1498 "GSDIR successfully completed",
1499 JOptionPane.INFORMATION_MESSAGE );
1503 void executeLineageInference() {
1504 if ( ( _mainpanel.getCurrentPhylogeny() == null ) || ( _mainpanel.getCurrentPhylogeny().isEmpty() ) ) {
1507 if ( !_mainpanel.getCurrentPhylogeny().isRooted() ) {
1508 JOptionPane.showMessageDialog( this,
1509 "Phylogeny is not rooted.",
1510 "Cannot infer ancestral taxonomies",
1511 JOptionPane.ERROR_MESSAGE );
1514 final AncestralTaxonomyInferrer inferrer = new AncestralTaxonomyInferrer( this,
1515 _mainpanel.getCurrentTreePanel(),
1516 _mainpanel.getCurrentPhylogeny()
1518 new Thread( inferrer ).start();
1521 boolean GAndSDoHaveMoreThanOneSpeciesInComman( final Phylogeny gene_tree ) {
1522 if ( ( gene_tree == null ) || gene_tree.isEmpty() ) {
1523 JOptionPane.showMessageDialog( this,
1524 "Gene tree and species tree have no species in common.",
1526 JOptionPane.ERROR_MESSAGE );
1529 else if ( gene_tree.getNumberOfExternalNodes() < 2 ) {
1530 JOptionPane.showMessageDialog( this,
1531 "Gene tree and species tree have only one species in common.",
1533 JOptionPane.ERROR_MESSAGE );
1541 ControlPanel getControlPanel() {
1542 return getMainPanel().getControlPanel();
1545 File getCurrentDir() {
1546 if ( ( _current_dir == null ) || !_current_dir.canRead() ) {
1547 if ( ForesterUtil.isWindows() ) {
1549 _current_dir = new File( WindowsUtils.getCurrentUserDesktopPath() );
1551 catch ( final Exception e ) {
1552 _current_dir = null;
1556 if ( ( _current_dir == null ) || !_current_dir.canRead() ) {
1557 if ( System.getProperty( "user.home" ) != null ) {
1558 _current_dir = new File( System.getProperty( "user.home" ) );
1560 else if ( System.getProperty( "user.dir" ) != null ) {
1561 _current_dir = new File( System.getProperty( "user.dir" ) );
1564 return _current_dir;
1567 TreePanel getCurrentTreePanel() {
1568 return getMainPanel().getCurrentTreePanel();
1571 JMenu getHelpMenu() {
1575 JCheckBoxMenuItem getlabelDirectionCbmi() {
1576 return _label_direction_cbmi;
1579 JMenuBar getMenuBarOfMainFrame() {
1583 final Phylogeny getSpeciesTree() {
1584 return _species_tree;
1587 void initializeTypeMenu( final Options options ) {
1588 setTypeMenuToAllUnselected();
1589 switch ( options.getPhylogenyGraphicsType() ) {
1591 _convex_type_cbmi.setSelected( true );
1594 _curved_type_cbmi.setSelected( true );
1597 _euro_type_cbmi.setSelected( true );
1600 _rounded_type_cbmi.setSelected( true );
1603 _triangular_type_cbmi.setSelected( true );
1606 _unrooted_type_cbmi.setSelected( true );
1609 _circular_type_cbmi.setSelected( true );
1612 _rectangular_type_cbmi.setSelected( true );
1617 boolean isOKforSDI( final boolean species_tree_has_to_binary, final boolean gene_tree_has_to_binary ) {
1618 if ( ( _mainpanel.getCurrentPhylogeny() == null ) || _mainpanel.getCurrentPhylogeny().isEmpty() ) {
1621 else if ( ( getSpeciesTree() == null ) || getSpeciesTree().isEmpty() ) {
1622 JOptionPane.showMessageDialog( this,
1623 "No species tree loaded",
1624 "Cannot execute GSDI",
1625 JOptionPane.ERROR_MESSAGE );
1628 else if ( species_tree_has_to_binary && !getSpeciesTree().isCompletelyBinary() ) {
1629 JOptionPane.showMessageDialog( this,
1630 "Species tree is not completely binary",
1631 "Cannot execute GSDI",
1632 JOptionPane.ERROR_MESSAGE );
1635 else if ( gene_tree_has_to_binary && !_mainpanel.getCurrentPhylogeny().isCompletelyBinary() ) {
1636 JOptionPane.showMessageDialog( this,
1637 "Gene tree is not completely binary",
1638 "Cannot execute GSDI",
1639 JOptionPane.ERROR_MESSAGE );
1647 boolean isSubtreeDisplayed() {
1648 if ( getCurrentTreePanel() != null ) {
1649 if ( getCurrentTreePanel().isCurrentTreeIsSubtree() ) {
1651 .showMessageDialog( this,
1652 "This operation can only be performed on a complete tree, not on the currently displayed sub-tree only.",
1653 "Operation can not be exectuted on a sub-tree",
1654 JOptionPane.WARNING_MESSAGE );
1661 void midpointRoot() {
1662 if ( _mainpanel.getCurrentTreePanel() != null ) {
1663 _mainpanel.getCurrentTreePanel().midpointRoot();
1667 void readPhylogeniesFromWebservice( final int i ) {
1668 final UrlTreeReader reader = new UrlTreeReader( this, i );
1669 new Thread( reader ).start();
1672 void removeAllTextFrames() {
1673 for( final TextFrame tf : _textframes ) {
1678 _textframes.clear();
1681 void resetSearch() {
1682 getMainPanel().getCurrentTreePanel().setFoundNodes0( null );
1683 getMainPanel().getCurrentTreePanel().setFoundNodes1( null );
1684 getMainPanel().getControlPanel().setSearchFoundCountsOnLabel0( 0 );
1685 getMainPanel().getControlPanel().getSearchFoundCountsLabel0().setVisible( false );
1686 getMainPanel().getControlPanel().getSearchTextField0().setText( "" );
1687 getMainPanel().getControlPanel().getSearchResetButton0().setEnabled( false );
1688 getMainPanel().getControlPanel().getSearchResetButton0().setVisible( false );
1689 getMainPanel().getControlPanel().setSearchFoundCountsOnLabel1( 0 );
1690 getMainPanel().getControlPanel().getSearchFoundCountsLabel1().setVisible( false );
1691 getMainPanel().getControlPanel().getSearchTextField1().setText( "" );
1692 getMainPanel().getControlPanel().getSearchResetButton1().setEnabled( false );
1693 getMainPanel().getControlPanel().getSearchResetButton1().setVisible( false );
1696 void setConfiguration( final Configuration configuration ) {
1697 _configuration = configuration;
1700 void setCurrentDir( final File current_dir ) {
1701 _current_dir = current_dir;
1704 void setInferenceManager( final InferenceManager i ) {
1705 _inference_manager = i;
1708 void setOptions( final Options options ) {
1712 void setSelectedTypeInTypeMenu( final PHYLOGENY_GRAPHICS_TYPE type ) {
1713 setTypeMenuToAllUnselected();
1716 _circular_type_cbmi.setSelected( true );
1719 _convex_type_cbmi.setSelected( true );
1722 _curved_type_cbmi.setSelected( true );
1725 _euro_type_cbmi.setSelected( true );
1728 _rounded_type_cbmi.setSelected( true );
1731 _rectangular_type_cbmi.setSelected( true );
1734 _triangular_type_cbmi.setSelected( true );
1737 _unrooted_type_cbmi.setSelected( true );
1740 throw new IllegalArgumentException( "unknown type: " + type );
1744 final void setSpeciesTree( final Phylogeny species_tree ) {
1745 _species_tree = species_tree;
1748 void setTypeMenuToAllUnselected() {
1749 _convex_type_cbmi.setSelected( false );
1750 _curved_type_cbmi.setSelected( false );
1751 _euro_type_cbmi.setSelected( false );
1752 _rounded_type_cbmi.setSelected( false );
1753 _triangular_type_cbmi.setSelected( false );
1754 _rectangular_type_cbmi.setSelected( false );
1755 _unrooted_type_cbmi.setSelected( false );
1756 _circular_type_cbmi.setSelected( false );
1759 void switchColors() {
1760 final TreeColorSet colorset = _mainpanel.getTreeColorSet();
1761 final ColorSchemeChooser csc = new ColorSchemeChooser( getMainPanel(), colorset );
1762 csc.setVisible( true );
1766 if ( _mainpanel.getCurrentTreePanel() != null ) {
1767 _mainpanel.getCurrentTreePanel().taxColor();
1771 void typeChanged( final Object o ) {
1772 updateTypeCheckboxes( getOptions(), o );
1773 updateOptions( getOptions() );
1774 if ( getCurrentTreePanel() != null ) {
1775 final PHYLOGENY_GRAPHICS_TYPE previous_type = getCurrentTreePanel().getPhylogenyGraphicsType();
1776 final PHYLOGENY_GRAPHICS_TYPE new_type = getOptions().getPhylogenyGraphicsType();
1777 if ( ( ( previous_type == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) && ( new_type != PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) )
1778 || ( ( previous_type == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) && ( new_type != PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) )
1779 || ( ( previous_type != PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) && ( new_type == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) )
1780 || ( ( previous_type != PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) && ( new_type == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) ) ) {
1781 getCurrentTreePanel().getControlPanel().showWhole();
1783 if ( getCurrentTreePanel().isPhyHasBranchLengths() && ( new_type != PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) ) {
1784 getCurrentTreePanel().getControlPanel().setDrawPhylogramEnabled( true );
1787 getCurrentTreePanel().getControlPanel().setDrawPhylogramEnabled( false );
1789 getCurrentTreePanel().setPhylogenyGraphicsType( getOptions().getPhylogenyGraphicsType() );
1790 updateScreenTextAntialias( getMainPanel().getTreePanels() );
1791 if ( getCurrentTreePanel().getControlPanel().getDynamicallyHideData() != null ) {
1792 if ( new_type == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) {
1793 getCurrentTreePanel().getControlPanel().getDynamicallyHideData().setEnabled( false );
1796 getCurrentTreePanel().getControlPanel().getDynamicallyHideData().setEnabled( true );
1802 void updateOptions( final Options options ) {
1803 options.setAntialiasScreen( ( _screen_antialias_cbmi != null ) && _screen_antialias_cbmi.isSelected() );
1804 options.setBackgroundColorGradient( ( _background_gradient_cbmi != null )
1805 && _background_gradient_cbmi.isSelected() );
1806 options.setShowDomainLabels( ( _show_domain_labels != null ) && _show_domain_labels.isSelected() );
1807 options.setShowAnnotationRefSource( ( _show_annotation_ref_source != null )
1808 && _show_annotation_ref_source.isSelected() );
1809 options.setAbbreviateScientificTaxonNames( ( _abbreviate_scientific_names != null )
1810 && _abbreviate_scientific_names.isSelected() );
1811 options.setColorLabelsSameAsParentBranch( ( _color_labels_same_as_parent_branch != null )
1812 && _color_labels_same_as_parent_branch.isSelected() );
1813 options.setShowDefaultNodeShapesInternal( ( _show_default_node_shapes_internal_cbmi != null )
1814 && _show_default_node_shapes_internal_cbmi.isSelected() );
1815 options.setShowDefaultNodeShapesExternal( ( _show_default_node_shapes_external_cbmi != null )
1816 && _show_default_node_shapes_external_cbmi.isSelected() );
1817 options.setShowDefaultNodeShapesForMarkedNodes( ( _show_default_node_shapes_for_marked_cbmi != null )
1818 && _show_default_node_shapes_for_marked_cbmi.isSelected() );
1819 if ( ( _non_lined_up_cladograms_rbmi != null ) && ( _non_lined_up_cladograms_rbmi.isSelected() ) ) {
1820 options.setCladogramType( CLADOGRAM_TYPE.NON_LINED_UP );
1822 else if ( ( _uniform_cladograms_rbmi != null ) && ( _uniform_cladograms_rbmi.isSelected() ) ) {
1823 options.setCladogramType( CLADOGRAM_TYPE.TOTAL_NODE_SUM_DEP );
1825 else if ( ( _ext_node_dependent_cladogram_rbmi != null ) && ( _ext_node_dependent_cladogram_rbmi.isSelected() ) ) {
1826 options.setCladogramType( CLADOGRAM_TYPE.EXT_NODE_SUM_DEP );
1828 options.setSearchCaseSensitive( ( _search_case_senstive_cbmi != null )
1829 && _search_case_senstive_cbmi.isSelected() );
1830 if ( ( _show_scale_cbmi != null ) && _show_scale_cbmi.isEnabled() ) {
1831 options.setShowScale( _show_scale_cbmi.isSelected() );
1833 if ( _label_direction_cbmi != null ) {
1834 if ( _label_direction_cbmi.isSelected() ) {
1835 options.setNodeLabelDirection( NODE_LABEL_DIRECTION.RADIAL );
1838 options.setNodeLabelDirection( NODE_LABEL_DIRECTION.HORIZONTAL );
1841 options.setShowOverview( ( _show_overview_cbmi != null ) && _show_overview_cbmi.isSelected() );
1842 options.setShowConfidenceStddev( ( _show_confidence_stddev_cbmi != null )
1843 && _show_confidence_stddev_cbmi.isSelected() );
1844 if ( ( _color_by_taxonomic_group_cbmi != null ) && _color_by_taxonomic_group_cbmi.isEnabled() ) {
1845 options.setColorByTaxonomicGroup( _color_by_taxonomic_group_cbmi.isSelected() );
1847 options.setAntialiasPrint( ( _antialias_print_cbmi != null ) && _antialias_print_cbmi.isSelected() );
1848 if ( ( _use_brackets_for_conf_in_nh_export_cbmi != null )
1849 && _use_brackets_for_conf_in_nh_export_cbmi.isSelected() ) {
1850 options.setNhConversionSupportValueStyle( NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS );
1852 else if ( ( _use_internal_names_for_conf_in_nh_export_cbmi != null )
1853 && _use_internal_names_for_conf_in_nh_export_cbmi.isSelected() ) {
1854 options.setNhConversionSupportValueStyle( NH_CONVERSION_SUPPORT_VALUE_STYLE.AS_INTERNAL_NODE_NAMES );
1857 options.setNhConversionSupportValueStyle( NH_CONVERSION_SUPPORT_VALUE_STYLE.NONE );
1859 options.setPrintBlackAndWhite( ( _print_black_and_white_cbmi != null )
1860 && _print_black_and_white_cbmi.isSelected() );
1861 options.setInternalNumberAreConfidenceForNhParsing( ( _internal_number_are_confidence_for_nh_parsing_cbmi != null )
1862 && _internal_number_are_confidence_for_nh_parsing_cbmi.isSelected() );
1863 if ( ( _extract_taxonomy_pfam_strict_rbmi != null ) && _extract_taxonomy_pfam_strict_rbmi.isSelected() ) {
1864 options.setTaxonomyExtraction( TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1866 else if ( ( _extract_taxonomy_pfam_relaxed_rbmi != null ) && _extract_taxonomy_pfam_relaxed_rbmi.isSelected() ) {
1867 options.setTaxonomyExtraction( TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
1869 else if ( ( _extract_taxonomy_agressive_rbmi != null ) && _extract_taxonomy_agressive_rbmi.isSelected() ) {
1870 options.setTaxonomyExtraction( TAXONOMY_EXTRACTION.AGGRESSIVE );
1872 else if ( ( _extract_taxonomy_no_rbmi != null ) && _extract_taxonomy_no_rbmi.isSelected() ) {
1873 options.setTaxonomyExtraction( TAXONOMY_EXTRACTION.NO );
1875 options.setReplaceUnderscoresInNhParsing( ( _replace_underscores_cbmi != null )
1876 && _replace_underscores_cbmi.isSelected() );
1877 options.setAllowErrorsInDistanceToParent( ( _allow_errors_in_distance_to_parent_cbmi != null )
1878 && _allow_errors_in_distance_to_parent_cbmi.isSelected() );
1879 options.setMatchWholeTermsOnly( ( _search_whole_words_only_cbmi != null )
1880 && _search_whole_words_only_cbmi.isSelected() );
1881 options.setSearchWithRegex( ( _search_with_regex_cbmi != null ) && _search_with_regex_cbmi.isSelected() );
1882 options.setInverseSearchResult( ( _inverse_search_result_cbmi != null )
1883 && _inverse_search_result_cbmi.isSelected() );
1884 if ( _graphics_export_visible_only_cbmi != null ) {
1885 options.setGraphicsExportVisibleOnly( _graphics_export_visible_only_cbmi.isSelected() );
1887 if ( ( _rectangular_type_cbmi != null ) && _rectangular_type_cbmi.isSelected() ) {
1888 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR );
1890 else if ( ( _triangular_type_cbmi != null ) && _triangular_type_cbmi.isSelected() ) {
1891 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.TRIANGULAR );
1893 else if ( ( _curved_type_cbmi != null ) && _curved_type_cbmi.isSelected() ) {
1894 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CURVED );
1896 else if ( ( _convex_type_cbmi != null ) && _convex_type_cbmi.isSelected() ) {
1897 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CONVEX );
1899 else if ( ( _euro_type_cbmi != null ) && _euro_type_cbmi.isSelected() ) {
1900 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE );
1902 else if ( ( _rounded_type_cbmi != null ) && _rounded_type_cbmi.isSelected() ) {
1903 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.ROUNDED );
1905 else if ( ( _unrooted_type_cbmi != null ) && _unrooted_type_cbmi.isSelected() ) {
1906 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.UNROOTED );
1908 else if ( ( _circular_type_cbmi != null ) && _circular_type_cbmi.isSelected() ) {
1909 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CIRCULAR );
1911 if ( ( _right_line_up_domains_cbmi != null ) && _right_line_up_domains_cbmi.isEnabled() ) {
1912 options.setRightLineUpDomains( _right_line_up_domains_cbmi.isSelected() );
1914 if ( ( _line_up_renderable_data_cbmi != null ) && _line_up_renderable_data_cbmi.isEnabled() ) {
1915 options.setLineUpRendarableNodeData( _line_up_renderable_data_cbmi.isSelected() );
1917 if ( ( _color_all_found_nodes_when_coloring_subtree_cbmi != null ) && _color_all_found_nodes_when_coloring_subtree_cbmi.isEnabled() ) {
1918 options.setColorAllFoundNodesWhenColoringSubtree( _color_all_found_nodes_when_coloring_subtree_cbmi.isSelected() );
1920 if ( ( _parse_beast_style_extended_nexus_tags_cbmi != null ) && _parse_beast_style_extended_nexus_tags_cbmi.isEnabled() ) {
1921 options.setParseBeastStyleExtendedNexusTags(_parse_beast_style_extended_nexus_tags_cbmi.isSelected() );
1925 void updateTypeCheckboxes( final Options options, final Object o ) {
1926 setTypeMenuToAllUnselected();
1927 ( ( JCheckBoxMenuItem ) o ).setSelected( true );
1930 void viewAsNexus() {
1931 if ( ( _mainpanel.getCurrentPhylogeny() != null ) && !_mainpanel.getCurrentPhylogeny().isEmpty() ) {
1932 String title = "Nexus";
1933 if ( !ForesterUtil.isEmpty( _mainpanel.getCurrentPhylogeny().getName() ) ) {
1934 title = "\"" + getMainPanel().getCurrentPhylogeny().getName() + "\" in " + title;
1936 showTextFrame( _mainpanel.getCurrentPhylogeny().toNexus( getOptions().getNhConversionSupportValueStyle() ),
1942 if ( ( _mainpanel.getCurrentPhylogeny() != null ) && !_mainpanel.getCurrentPhylogeny().isEmpty() ) {
1943 String title = "New Hampshire";
1944 if ( !ForesterUtil.isEmpty( _mainpanel.getCurrentPhylogeny().getName() ) ) {
1945 title = "\"" + getMainPanel().getCurrentPhylogeny().getName() + "\" in " + title;
1947 showTextFrame( _mainpanel.getCurrentPhylogeny().toNewHampshire( getOptions()
1948 .getNhConversionSupportValueStyle() ),
1954 if ( ( _mainpanel.getCurrentPhylogeny() != null ) && !_mainpanel.getCurrentPhylogeny().isEmpty() ) {
1955 String title = "phyloXML";
1956 if ( !ForesterUtil.isEmpty( _mainpanel.getCurrentPhylogeny().getName() ) ) {
1957 title = "\"" + getMainPanel().getCurrentPhylogeny().getName() + "\" in " + title;
1959 showTextFrame( _mainpanel.getCurrentPhylogeny().toPhyloXML( 0 ), title );
1963 private static void cycleNodeDataReturn( final Options op, final Configuration conf ) {
1964 switch ( op.getExtDescNodeDataToReturn() ) {
1966 op.setExtDescNodeDataToReturn( NodeDataField.DOMAINS_ALL );
1969 op.setExtDescNodeDataToReturn( NodeDataField.DOMAINS_COLLAPSED_PER_PROTEIN );
1971 case DOMAINS_COLLAPSED_PER_PROTEIN:
1972 op.setExtDescNodeDataToReturn( NodeDataField.SEQ_ANNOTATIONS );
1974 case SEQ_ANNOTATIONS:
1975 op.setExtDescNodeDataToReturn( NodeDataField.GO_TERM_IDS );
1978 op.setExtDescNodeDataToReturn( NodeDataField.SEQUENCE_MOL_SEQ_FASTA );
1980 case SEQUENCE_MOL_SEQ_FASTA:
1981 if ( ( conf != null ) && ( conf.getExtDescNodeDataToReturn() != null )
1982 && ( conf.getExtDescNodeDataToReturn() != NodeDataField.DOMAINS_ALL )
1983 && ( conf.getExtDescNodeDataToReturn() != NodeDataField.DOMAINS_COLLAPSED_PER_PROTEIN )
1984 && ( conf.getExtDescNodeDataToReturn() != NodeDataField.SEQ_ANNOTATIONS )
1985 && ( conf.getExtDescNodeDataToReturn() != NodeDataField.GO_TERM_IDS )
1986 && ( conf.getExtDescNodeDataToReturn() != NodeDataField.SEQUENCE_MOL_SEQ_FASTA ) ) {
1987 op.setExtDescNodeDataToReturn( conf.getExtDescNodeDataToReturn() );
1990 op.setExtDescNodeDataToReturn( NodeDataField.UNKNOWN );
1994 op.setExtDescNodeDataToReturn( NodeDataField.UNKNOWN );
1999 * Display the about box.
2001 static void about() {
2002 final StringBuffer about = new StringBuffer( "Archaeopteryx\nVersion " + AptxConstants.VERSION + "\n" );
2003 about.append( "Copyright (C) 2016 Christian M Zmasek\n" );
2004 about.append( "All Rights Reserved\n" );
2005 about.append( "License: GNU Lesser General Public License (LGPL)\n" );
2006 about.append( "Last modified: " + AptxConstants.PRG_DATE + "\n" );
2007 about.append( "Based on: " + ForesterUtil.getForesterLibraryInformation() + "\n" );
2008 about.append( "phyloXML version : " + ForesterConstants.PHYLO_XML_VERSION + "\n" );
2009 about.append( "phyloXML location: " + ForesterConstants.PHYLO_XML_LOCATION + "\n" );
2010 if ( !ForesterUtil.isEmpty( ForesterUtil.JAVA_VERSION ) && !ForesterUtil.isEmpty( ForesterUtil.JAVA_VENDOR ) ) {
2011 about.append( "[your Java version: " + ForesterUtil.JAVA_VERSION + " " + ForesterUtil.JAVA_VENDOR + "]\n" );
2013 if ( !ForesterUtil.isEmpty( ForesterUtil.OS_NAME ) && !ForesterUtil.isEmpty( ForesterUtil.OS_ARCH )
2014 && !ForesterUtil.isEmpty( ForesterUtil.OS_VERSION ) ) {
2015 about.append( "[your OS: " + ForesterUtil.OS_NAME + " " + ForesterUtil.OS_ARCH + " "
2016 + ForesterUtil.OS_VERSION + "]\n" );
2018 final Runtime rt = java.lang.Runtime.getRuntime();
2019 final long free_memory = rt.freeMemory() / 1000000;
2020 final long total_memory = rt.totalMemory() / 1000000;
2021 about.append( "[free memory: " + free_memory + "MB, total memory: " + total_memory + "MB]\n" );
2022 about.append( "[locale: " + Locale.getDefault() + "]\n" );
2023 about.append( "References:\n" );
2024 about.append( AptxConstants.PHYLOXML_REFERENCE_SHORT + "\n" );
2025 about.append( "For more information & download:\n" );
2026 about.append( AptxConstants.APTX_WEB_SITE + "\n" );
2027 about.append( "Documentation:\n" );
2028 about.append( AptxConstants.APTX_DOC_SITE + "\n" );
2029 about.append( "Comments: " + AptxConstants.AUTHOR_EMAIL );
2030 JOptionPane.showMessageDialog( null, about, AptxConstants.PRG_NAME, JOptionPane.PLAIN_MESSAGE );
2033 static void chooseNodeSize( final Options options, final Component parent ) {
2034 final String s = ( String ) JOptionPane.showInputDialog( parent,
2035 "Please enter the default size for node shapes.\n"
2036 + "[current value: "
2037 + options.getDefaultNodeShapeSize() + "]\n",
2039 JOptionPane.QUESTION_MESSAGE,
2042 options.getDefaultNodeShapeSize() );
2043 if ( !ForesterUtil.isEmpty( s ) ) {
2044 boolean success = true;
2046 final String m_str = s.trim();
2047 if ( !ForesterUtil.isEmpty( m_str ) ) {
2049 m = Double.parseDouble( m_str );
2051 catch ( final Exception ex ) {
2058 if ( success && ( m >= 0.0 ) ) {
2059 final short size = ForesterUtil.roundToShort( m );
2060 if ( size >= 0.0 ) {
2061 options.setDefaultNodeShapeSize( size );
2067 static String createCurrentFontDesc( final TreeFontSet tree_font_set ) {
2068 return tree_font_set.getLargeFont().getFamily() + " " + tree_font_set.getLargeFont().getSize();
2071 static JMenu createMenu( final String title, final Configuration conf ) {
2072 final JMenu jmenu = new JMenu( title );
2073 if ( !conf.isUseNativeUI() ) {
2074 jmenu.setFont( MainFrame.menu_font );
2075 jmenu.setBackground( conf.getGuiMenuBackgroundColor() );
2076 jmenu.setForeground( conf.getGuiMenuTextColor() );
2081 static JMenuItem customizeMenuItemAsLabel( final JMenuItem label, final Configuration configuration ) {
2082 label.setFont( MainFrame.menu_font.deriveFont( Font.BOLD ) );
2083 if ( !configuration.isUseNativeUI() ) {
2084 label.setBackground( configuration.getGuiMenuBackgroundColor() );
2085 label.setForeground( configuration.getGuiMenuTextColor() );
2086 label.setOpaque( true );
2088 label.setSelected( false );
2089 label.setEnabled( false );
2093 static void cycleNodeFill( final Options op ) {
2094 switch ( op.getDefaultNodeFill() ) {
2096 op.setDefaultNodeFill( NodeFill.SOLID );
2099 op.setDefaultNodeFill( NodeFill.GRADIENT );
2102 op.setDefaultNodeFill( NodeFill.NONE );
2105 throw new RuntimeException( "unknown fill: " + op.getDefaultNodeFill() );
2109 static void cycleNodeShape( final Options op ) {
2110 switch ( op.getDefaultNodeShape() ) {
2112 op.setDefaultNodeShape( NodeShape.RECTANGLE );
2115 op.setDefaultNodeShape( NodeShape.CIRCLE );
2118 throw new RuntimeException( "unknown shape: " + op.getDefaultNodeShape() );
2122 static void cycleOverview( final Options op, final TreePanel tree_panel ) {
2123 switch ( op.getOvPlacement() ) {
2125 op.setOvPlacement( Options.OVERVIEW_PLACEMENT_TYPE.UPPER_LEFT );
2128 op.setOvPlacement( Options.OVERVIEW_PLACEMENT_TYPE.LOWER_LEFT );
2131 op.setOvPlacement( Options.OVERVIEW_PLACEMENT_TYPE.UPPER_RIGHT );
2134 op.setOvPlacement( Options.OVERVIEW_PLACEMENT_TYPE.LOWER_RIGHT );
2137 throw new RuntimeException( "unknown placement: " + op.getOvPlacement() );
2139 if ( tree_panel != null ) {
2140 tree_panel.updateOvSettings();
2144 static void exceptionOccuredDuringSaveAs( final Exception e, final TreePanel tp, final Component comp ) {
2146 tp.setArrowCursor();
2148 catch ( final Exception ex ) {
2151 JOptionPane.showMessageDialog( comp, "Exception" + e, "Error during File|SaveAs", JOptionPane.ERROR_MESSAGE );
2154 static void print( final TreePanel tp, final Options op, final Component c ) {
2155 if ( ( tp == null ) || ( tp.getPhylogeny() == null ) || tp.getPhylogeny().isEmpty() ) {
2158 final String job_name = AptxConstants.PRG_NAME;
2159 boolean error = false;
2160 String printer_name = null;
2162 printer_name = Printer.print( tp, job_name );
2164 catch ( final Exception e ) {
2166 JOptionPane.showMessageDialog( c, e.getMessage(), "Printing Error", JOptionPane.ERROR_MESSAGE );
2168 if ( !error && ( printer_name != null ) ) {
2169 String msg = "Printing data sent to printer";
2170 if ( printer_name.length() > 1 ) {
2171 msg += " [" + printer_name + "]";
2173 JOptionPane.showMessageDialog( c, msg, "Printing...", JOptionPane.INFORMATION_MESSAGE );
2175 if ( !op.isPrintUsingActualSize() ) {
2176 tp.getControlPanel().showWhole();
2180 static void printPhylogenyToPdf( final String file_name,
2183 final Component comp ) {
2185 String pdf_written_to = "";
2186 boolean error = false;
2188 if ( opts.isPrintUsingActualSize() ) {
2189 pdf_written_to = PdfExporter.writePhylogenyToPdf( file_name, tp, tp.getWidth() , tp.getHeight() );
2195 catch ( final IOException e ) {
2197 JOptionPane.showMessageDialog( comp, e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE );
2200 if ( !ForesterUtil.isEmpty( pdf_written_to ) ) {
2201 JOptionPane.showMessageDialog( comp,
2202 "Wrote PDF to: " + pdf_written_to,
2204 JOptionPane.INFORMATION_MESSAGE );
2207 JOptionPane.showMessageDialog( comp,
2208 "There was an unknown problem when attempting to write to PDF file: \""
2211 JOptionPane.ERROR_MESSAGE );
2214 if ( !opts.isPrintUsingActualSize() ) {
2215 tp.getControlPanel().showWhole();
2219 static void setCycleDataReturnMenuItem( final JMenuItem mi, final Options options ) {
2220 if ( ( options != null ) && ( options.getExtDescNodeDataToReturn() != null ) ) {
2221 mi.setText( "Cycle Node Return Data... (current: " + options.getExtDescNodeDataToReturn().toString() + ")" );
2224 mi.setText( "Cycle Node Return Data..." );
2228 static void setCycleNodeFillMenuItem( final JMenuItem mi, final Options options ) {
2229 if ( ( options != null ) && ( options.getDefaultNodeFill() != null ) ) {
2230 mi.setText( "Cycle Node Shape Fill Type... (current: "
2231 + options.getDefaultNodeFill().toString().toLowerCase() + ")" );
2234 mi.setText( "Cycle Node Shape Fill Type..." );
2238 static void setCycleNodeShapeMenuItem( final JMenuItem mi, final Options options ) {
2239 if ( ( options != null ) && ( options.getDefaultNodeShape() != null ) ) {
2240 mi.setText( "Cycle Node Shape Fill Type... (current: "
2241 + options.getDefaultNodeShape().toString().toLowerCase() + ")" );
2244 mi.setText( "Cycle Node Shape Fill Type..." );
2248 static void setOvPlacementColorChooseMenuItem( final JMenuItem mi, final Options options ) {
2249 if ( ( options != null ) && ( options.getOvPlacement() != null ) ) {
2250 mi.setText( "Cycle Overview Placement... (current: " + options.getOvPlacement() + ")" );
2253 mi.setText( "Cycle Overview Placement..." );
2257 static void setTextColorChooseMenuItem( final JMenuItem mi, final TreePanel tree_panel ) {
2258 if ( ( tree_panel != null ) && ( tree_panel.getTreeColorSet() != null ) ) {
2259 mi.setText( "Select Color Scheme... (current: " + tree_panel.getTreeColorSet().getCurrentColorSchemeName()
2263 mi.setText( "Select Color Scheme..." );
2267 static void setTextForFontChooserMenuItem( final JMenuItem mi, final String font_desc ) {
2268 mi.setText( "Select Default Font... (current: " + font_desc + ")" );
2271 static void setTextForPdfLineWidthChooserMenuItem( final JMenuItem mi, final Options o ) {
2272 mi.setText( "Enter Default Line Width for PDF Export... (current: " + o.getPrintLineWidth() + ")" );
2275 static void setTextMinSupportMenuItem( final JMenuItem mi, final Options options, final TreePanel current_tree_panel ) {
2276 if ( ( current_tree_panel == null ) || ( current_tree_panel.getPhylogeny() == null ) ) {
2277 mi.setEnabled( true );
2279 else if ( AptxUtil.isHasAtLeastOneBranchWithSupportValues( current_tree_panel.getPhylogeny() ) ) {
2280 mi.setEnabled( true );
2283 mi.setEnabled( false );
2285 mi.setText( "Enter Min Confidence Value... (current: " + options.getMinConfidenceValue() + ")" );
2288 static void setTextNodeSizeMenuItem( final JMenuItem mi, final Options options ) {
2289 mi.setText( "Enter Default Node Shape Size... (current: " + options.getDefaultNodeShapeSize() + ")" );
2292 static void updateScreenTextAntialias( final List<TreePanel> treepanels ) {
2293 for( final TreePanel tree_panel : treepanels ) {
2294 tree_panel.setTextAntialias();
2298 static boolean writeAsNewHampshire( final TreePanel tp, final Options op, boolean exception, final File file ) {
2300 final PhylogenyWriter writer = new PhylogenyWriter();
2301 writer.toNewHampshire( tp.getPhylogeny(), true, op.getNhConversionSupportValueStyle(), file );
2303 catch ( final Exception e ) {
2305 exceptionOccuredDuringSaveAs( e, tp, tp );
2310 static boolean writeAsNexus( final TreePanel tp, final Options op, boolean exception, final File file ) {
2312 final PhylogenyWriter writer = new PhylogenyWriter();
2313 writer.toNexus( file, tp.getPhylogeny(), op.getNhConversionSupportValueStyle() );
2315 catch ( final Exception e ) {
2317 exceptionOccuredDuringSaveAs( e, tp, tp );
2322 static boolean writeAsPhyloXml( final TreePanel tp, final Options op, boolean exception, final File file ) {
2324 final PhylogenyWriter writer = new PhylogenyWriter();
2325 writer.toPhyloXML( file, tp.getPhylogeny(), 0 );
2327 catch ( final Exception e ) {
2329 exceptionOccuredDuringSaveAs( e, tp, tp );
2334 static void writePhylogenyToGraphicsFile( final String file_name,
2335 final GraphicsExportType type,
2337 final Component comp,
2338 final Container contentpane ) {
2339 mp.getCurrentTreePanel().calcParametersForPainting( mp.getCurrentTreePanel().getWidth(),
2340 mp.getCurrentTreePanel().getHeight() );
2341 String file_written_to = "";
2342 boolean error = false;
2344 file_written_to = AptxUtil.writePhylogenyToGraphicsFile( file_name,
2345 mp.getCurrentTreePanel().getWidth(),
2346 mp.getCurrentTreePanel().getHeight(),
2347 mp.getCurrentTreePanel(),
2348 mp.getControlPanel(),
2352 catch ( final IOException e ) {
2354 JOptionPane.showMessageDialog( comp, e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE );
2357 if ( ( file_written_to != null ) && ( file_written_to.length() > 0 ) ) {
2358 JOptionPane.showMessageDialog( comp,
2359 "Wrote image to: " + file_written_to,
2361 JOptionPane.INFORMATION_MESSAGE );
2364 JOptionPane.showMessageDialog( comp,
2365 "There was an unknown problem when attempting to write to an image file: \""
2368 JOptionPane.ERROR_MESSAGE );
2371 contentpane.repaint();
2374 static File writeToFile( final Phylogeny t,
2376 final JFileChooser save_filechooser,
2377 final File current_dir,
2378 final Container contentpane,
2379 final Component comp ) {
2380 File new_file = null;
2384 String initial_filename = null;
2385 if ( mp.getCurrentTreePanel().getTreeFile() != null ) {
2387 initial_filename = mp.getCurrentTreePanel().getTreeFile().getCanonicalPath();
2389 catch ( final IOException e ) {
2390 initial_filename = null;
2393 if ( !ForesterUtil.isEmpty( initial_filename ) ) {
2394 save_filechooser.setSelectedFile( new File( initial_filename ) );
2397 save_filechooser.setSelectedFile( new File( "" ) );
2399 final File my_dir = current_dir;
2400 if ( my_dir != null ) {
2401 save_filechooser.setCurrentDirectory( my_dir );
2403 final int result = save_filechooser.showSaveDialog( contentpane );
2404 final File file = save_filechooser.getSelectedFile();
2405 new_file = save_filechooser.getCurrentDirectory();
2406 boolean exception = false;
2407 if ( ( file != null ) && ( result == JFileChooser.APPROVE_OPTION ) ) {
2408 if ( file.exists() ) {
2409 final int i = JOptionPane.showConfirmDialog( comp,
2410 file + " already exists.\nOverwrite?",
2412 JOptionPane.OK_CANCEL_OPTION,
2413 JOptionPane.QUESTION_MESSAGE );
2414 if ( i != JOptionPane.OK_OPTION ) {
2418 final File to = new File( file.getAbsoluteFile().toString() + AptxConstants.BACKUP_FILE_SUFFIX );
2420 ForesterUtil.copyFile( file, to );
2422 catch ( final Exception e ) {
2423 JOptionPane.showMessageDialog( comp,
2424 "Failed to create backup copy " + to,
2425 "Failed to Create Backup Copy",
2426 JOptionPane.WARNING_MESSAGE );
2431 catch ( final Exception e ) {
2432 JOptionPane.showMessageDialog( comp,
2433 "Failed to delete: " + file,
2435 JOptionPane.WARNING_MESSAGE );
2439 if ( save_filechooser.getFileFilter() == MainFrame.nhfilter ) {
2440 exception = writeAsNewHampshire( mp.getCurrentTreePanel(), mp.getOptions(), exception, file );
2442 else if ( save_filechooser.getFileFilter() == MainFrame.xmlfilter ) {
2443 exception = writeAsPhyloXml( mp.getCurrentTreePanel(), mp.getOptions(), exception, file );
2445 else if ( save_filechooser.getFileFilter() == MainFrame.nexusfilter ) {
2446 exception = writeAsNexus( mp.getCurrentTreePanel(), mp.getOptions(), exception, file );
2450 final String file_name = file.getName().trim().toLowerCase();
2451 if ( file_name.endsWith( ".nh" ) || file_name.endsWith( ".newick" ) || file_name.endsWith( ".phy" )
2452 || file_name.endsWith( ".tree" ) ) {
2453 exception = writeAsNewHampshire( mp.getCurrentTreePanel(), mp.getOptions(), exception, file );
2455 else if ( file_name.endsWith( ".nex" ) || file_name.endsWith( ".nexus" ) ) {
2456 exception = writeAsNexus( mp.getCurrentTreePanel(), mp.getOptions(), exception, file );
2460 exception = writeAsPhyloXml( mp.getCurrentTreePanel(), mp.getOptions(), exception, file );
2464 mp.setTitleOfSelectedTab( file.getName() );
2465 mp.getCurrentTreePanel().setTreeFile( file );
2466 mp.getCurrentTreePanel().setEdited( false );
2472 static File writeToGraphicsFile( final Phylogeny t,
2473 final GraphicsExportType type,
2475 final JFileChooser writetographics_filechooser,
2476 final Component component,
2477 final Container contentpane,
2478 final File current_dir ) {
2479 File new_dir = null;
2480 if ( ( t == null ) || t.isEmpty() ) {
2483 String initial_filename = "";
2484 if ( mp.getCurrentTreePanel().getTreeFile() != null ) {
2485 initial_filename = mp.getCurrentTreePanel().getTreeFile().toString();
2487 if ( initial_filename.indexOf( '.' ) > 0 ) {
2488 initial_filename = initial_filename.substring( 0, initial_filename.lastIndexOf( '.' ) );
2490 initial_filename = initial_filename + "." + type;
2491 writetographics_filechooser.setSelectedFile( new File( initial_filename ) );
2492 final File my_dir = current_dir;
2493 if ( my_dir != null ) {
2494 writetographics_filechooser.setCurrentDirectory( my_dir );
2496 final int result = writetographics_filechooser.showSaveDialog( contentpane );
2497 File file = writetographics_filechooser.getSelectedFile();
2498 //setCurrentDir( writetographics_filechooser.getCurrentDirectory() );
2499 new_dir = writetographics_filechooser.getCurrentDirectory();
2500 if ( ( file != null ) && ( result == JFileChooser.APPROVE_OPTION ) ) {
2501 if ( !file.toString().toLowerCase().endsWith( type.toString() ) ) {
2502 file = new File( file.toString() + "." + type );
2504 if ( file.exists() ) {
2505 final int i = JOptionPane.showConfirmDialog( component,
2506 file + " already exists. Overwrite?",
2508 JOptionPane.OK_CANCEL_OPTION,
2509 JOptionPane.WARNING_MESSAGE );
2510 if ( i != JOptionPane.OK_OPTION ) {
2517 catch ( final Exception e ) {
2518 JOptionPane.showMessageDialog( component,
2519 "Failed to delete: " + file,
2521 JOptionPane.WARNING_MESSAGE );
2525 writePhylogenyToGraphicsFile( file.toString(), type, mp, component, contentpane );
2530 static File writeToPdf( final Phylogeny t,
2532 final JFileChooser writetopdf_filechooser,
2533 final File curr_dir,
2534 final Container contentpane,
2535 final Component component ) {
2536 if ( ( t == null ) || t.isEmpty() ) {
2539 String initial_filename = "";
2540 if ( mp.getCurrentTreePanel().getTreeFile() != null ) {
2541 initial_filename = mp.getCurrentTreePanel().getTreeFile().toString();
2543 if ( initial_filename.indexOf( '.' ) > 0 ) {
2544 initial_filename = initial_filename.substring( 0, initial_filename.lastIndexOf( '.' ) );
2546 initial_filename = initial_filename + ".pdf";
2547 writetopdf_filechooser.setSelectedFile( new File( initial_filename ) );
2548 final File my_dir = curr_dir;
2549 if ( my_dir != null ) {
2550 writetopdf_filechooser.setCurrentDirectory( my_dir );
2552 final int result = writetopdf_filechooser.showSaveDialog( contentpane );
2553 File file = writetopdf_filechooser.getSelectedFile();
2554 // setCurrentDir( writetopdf_filechooser.getCurrentDirectory() );
2555 final File new_current_dir = writetopdf_filechooser.getCurrentDirectory();
2556 if ( ( file != null ) && ( result == JFileChooser.APPROVE_OPTION ) ) {
2557 if ( !file.toString().toLowerCase().endsWith( ".pdf" ) ) {
2558 file = new File( file.toString() + ".pdf" );
2560 if ( file.exists() ) {
2561 final int i = JOptionPane.showConfirmDialog( component,
2562 file + " already exists. Overwrite?",
2564 JOptionPane.OK_CANCEL_OPTION,
2565 JOptionPane.WARNING_MESSAGE );
2566 if ( i != JOptionPane.OK_OPTION ) {
2570 printPhylogenyToPdf( file.toString(), mp.getOptions(), mp.getCurrentTreePanel(), component );
2572 return new_current_dir;
2576 class DefaultFilter extends FileFilter {
2579 public boolean accept( final File f ) {
2580 final String file_name = f.getName().trim().toLowerCase();
2581 return file_name.endsWith( ".nh" ) || file_name.endsWith( ".newick" ) || file_name.endsWith( ".phy" )
2582 || file_name.endsWith( ".nwk" ) || file_name.endsWith( ".phb" ) || file_name.endsWith( ".ph" )
2583 || file_name.endsWith( ".tr" ) || file_name.endsWith( ".dnd" ) || file_name.endsWith( ".tree" )
2584 || file_name.endsWith( ".nhx" ) || file_name.endsWith( ".xml" ) || file_name.endsWith( ".phyloxml" )
2585 || file_name.endsWith( "phylo.xml" ) || file_name.endsWith( ".pxml" ) || file_name.endsWith( ".nexus" )
2586 || file_name.endsWith( ".nx" ) || file_name.endsWith( ".nex" ) || file_name.endsWith( ".tre" )
2587 || file_name.endsWith( ".zip" ) || file_name.endsWith( ".tol" ) || file_name.endsWith( ".tolxml" )
2588 || file_name.endsWith( ".con" ) || f.isDirectory();
2592 public String getDescription() {
2593 return "All supported files (*.xml, *.phyloxml, *phylo.xml, *.nhx, *.nh, *.newick, *.nex, *.nexus, *.phy, *.tre, *.tree, *.tol, ...)";
2597 class GraphicsFileFilter extends FileFilter {
2600 public boolean accept( final File f ) {
2601 final String file_name = f.getName().trim().toLowerCase();
2602 return file_name.endsWith( ".jpg" ) || file_name.endsWith( ".jpeg" ) || file_name.endsWith( ".png" )
2603 || file_name.endsWith( ".gif" ) || file_name.endsWith( ".bmp" ) || f.isDirectory();
2607 public String getDescription() {
2608 return "Image files (*.jpg, *.jpeg, *.png, *.gif, *.bmp)";
2612 class MsaFileFilter extends FileFilter {
2615 public boolean accept( final File f ) {
2616 final String file_name = f.getName().trim().toLowerCase();
2617 return file_name.endsWith( ".msa" ) || file_name.endsWith( ".aln" ) || file_name.endsWith( ".fasta" )
2618 || file_name.endsWith( ".fas" ) || file_name.endsWith( ".fa" ) || f.isDirectory();
2622 public String getDescription() {
2623 return "Multiple sequence alignment files (*.msa, *.aln, *.fasta, *.fa, *.fas)";
2627 class NexusFilter extends FileFilter {
2630 public boolean accept( final File f ) {
2631 final String file_name = f.getName().trim().toLowerCase();
2632 return file_name.endsWith( ".nex" ) || file_name.endsWith( ".nexus" ) || file_name.endsWith( ".nx" )
2633 || file_name.endsWith( ".tre" ) || f.isDirectory();
2637 public String getDescription() {
2638 return "Nexus files (*.nex, *.nexus, *.nx, *.tre)";
2642 class NHFilter extends FileFilter {
2645 public boolean accept( final File f ) {
2646 final String file_name = f.getName().trim().toLowerCase();
2647 return file_name.endsWith( ".nh" ) || file_name.endsWith( ".newick" ) || file_name.endsWith( ".phy" )
2648 || file_name.endsWith( ".tr" ) || file_name.endsWith( ".tree" ) || file_name.endsWith( ".dnd" )
2649 || file_name.endsWith( ".ph" ) || file_name.endsWith( ".phb" ) || file_name.endsWith( ".nwk" )
2654 public String getDescription() {
2655 return "New Hampshire - Newick files (*.nh, *.newick, *.phy, *.tree, *.dnd, *.tr, *.ph, *.phb, *.nwk)";
2659 class NHXFilter extends FileFilter {
2662 public boolean accept( final File f ) {
2663 final String file_name = f.getName().trim().toLowerCase();
2664 return file_name.endsWith( ".nhx" ) || f.isDirectory();
2668 public String getDescription() {
2669 return "NHX files (*.nhx) [deprecated]";
2673 class PdfFilter extends FileFilter {
2676 public boolean accept( final File f ) {
2677 return f.getName().trim().toLowerCase().endsWith( ".pdf" ) || f.isDirectory();
2681 public String getDescription() {
2682 return "PDF files (*.pdf)";
2686 class SequencesFileFilter extends FileFilter {
2689 public boolean accept( final File f ) {
2690 final String file_name = f.getName().trim().toLowerCase();
2691 return file_name.endsWith( ".fasta" ) || file_name.endsWith( ".fa" ) || file_name.endsWith( ".fas" )
2692 || file_name.endsWith( ".seqs" ) || f.isDirectory();
2696 public String getDescription() {
2697 return "Sequences files (*.fasta, *.fa, *.fas, *.seqs )";
2701 class TolFilter extends FileFilter {
2704 public boolean accept( final File f ) {
2705 final String file_name = f.getName().trim().toLowerCase();
2706 return ( file_name.endsWith( ".tol" ) || file_name.endsWith( ".tolxml" ) || file_name.endsWith( ".zip" ) || f
2707 .isDirectory() ) && ( !file_name.endsWith( ".xml.zip" ) );
2711 public String getDescription() {
2712 return "Tree of Life files (*.tol, *.tolxml)";
2716 class XMLFilter extends FileFilter {
2719 public boolean accept( final File f ) {
2720 final String file_name = f.getName().trim().toLowerCase();
2721 return file_name.endsWith( ".xml" ) || file_name.endsWith( ".phyloxml" ) || file_name.endsWith( "phylo.xml" )
2722 || file_name.endsWith( ".pxml" ) || file_name.endsWith( ".zip" ) || f.isDirectory();
2726 public String getDescription() {
2727 return "phyloXML files (*.xml, *.phyloxml, *phylo.xml, *.pxml, *.zip)";