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;
40 import java.util.NoSuchElementException;
42 import javax.swing.Box;
43 import javax.swing.JCheckBoxMenuItem;
44 import javax.swing.JFileChooser;
45 import javax.swing.JFrame;
46 import javax.swing.JInternalFrame;
47 import javax.swing.JLabel;
48 import javax.swing.JMenu;
49 import javax.swing.JMenuBar;
50 import javax.swing.JMenuItem;
51 import javax.swing.JOptionPane;
52 import javax.swing.JPanel;
53 import javax.swing.JRadioButtonMenuItem;
54 import javax.swing.JTextField;
55 import javax.swing.SwingUtilities;
56 import javax.swing.filechooser.FileFilter;
58 import org.forester.archaeopteryx.AptxUtil.GraphicsExportType;
59 import org.forester.archaeopteryx.Options.CLADOGRAM_TYPE;
60 import org.forester.archaeopteryx.Options.NODE_LABEL_DIRECTION;
61 import org.forester.archaeopteryx.Options.PHYLOGENY_GRAPHICS_TYPE;
62 import org.forester.archaeopteryx.tools.AncestralTaxonomyInferrer;
63 import org.forester.archaeopteryx.tools.InferenceManager;
64 import org.forester.archaeopteryx.tools.ProcessPool;
65 import org.forester.archaeopteryx.tools.ProcessRunning;
66 import org.forester.io.parsers.nhx.NHXParser.TAXONOMY_EXTRACTION;
67 import org.forester.io.writers.PhylogenyWriter;
68 import org.forester.phylogeny.Phylogeny;
69 import org.forester.phylogeny.PhylogenyMethods;
70 import org.forester.phylogeny.PhylogenyMethods.DESCENDANT_SORT_PRIORITY;
71 import org.forester.phylogeny.PhylogenyNode;
72 import org.forester.phylogeny.PhylogenyNode.NH_CONVERSION_SUPPORT_VALUE_STYLE;
73 import org.forester.phylogeny.data.Annotation;
74 import org.forester.phylogeny.data.NodeDataField;
75 import org.forester.phylogeny.data.NodeVisualData.NodeFill;
76 import org.forester.phylogeny.data.NodeVisualData.NodeShape;
77 import org.forester.phylogeny.iterators.PhylogenyNodeIterator;
78 import org.forester.sdi.GSDI;
79 import org.forester.sdi.GSDIR;
80 import org.forester.sdi.SDIException;
81 import org.forester.util.ForesterConstants;
82 import org.forester.util.ForesterUtil;
83 import org.forester.util.WindowsUtils;
85 public abstract class MainFrame extends JInternalFrame implements ActionListener {
87 public final static NHFilter nhfilter = new NHFilter();
88 public final static NHXFilter nhxfilter = new NHXFilter();
89 public final static XMLFilter xmlfilter = new XMLFilter();
90 public final static TolFilter tolfilter = new TolFilter();
91 public final static NexusFilter nexusfilter = new NexusFilter();
92 public final static PdfFilter pdffilter = new PdfFilter();
93 public final static GraphicsFileFilter graphicsfilefilter = new GraphicsFileFilter();
94 public final static MsaFileFilter msafilter = new MsaFileFilter();
95 public final static SequencesFileFilter seqsfilter = new SequencesFileFilter();
96 public final static DefaultFilter defaultfilter = new DefaultFilter();
97 static final String USE_MOUSEWHEEL_SHIFT_TO_ROTATE = "rotate with mousewheel + Shift (or A and S), D toggles between horizontal and radial labels";
98 static final String PHYLOXML_REF_TOOL_TIP = AptxConstants.PHYLOXML_REFERENCE; //TODO //FIXME
99 static final String APTX_REF_TOOL_TIP = AptxConstants.APTX_REFERENCE;
100 private static final long serialVersionUID = 3655000897845508358L;
101 final static Font menu_font = new Font( Configuration.getDefaultFontFamilyName(),
104 static final String TYPE_MENU_HEADER = "Type";
105 static final String RECTANGULAR_TYPE_CBMI_LABEL = "Rectangular";
106 static final String EURO_TYPE_CBMI_LABEL = "Euro Type";
107 static final String CURVED_TYPE_CBMI_LABEL = "Curved";
108 static final String TRIANGULAR_TYPE_CBMI_LABEL = "Triangular";
109 static final String CONVEX_TYPE_CBMI_LABEL = "Convex";
110 static final String ROUNDED_TYPE_CBMI_LABEL = "Rounded";
111 static final String UNROOTED_TYPE_CBMI_LABEL = "Unrooted (alpha)"; //TODO
112 static final String CIRCULAR_TYPE_CBMI_LABEL = "Circular (alpha)"; //TODO
113 static final String OPTIONS_HEADER = "Options";
114 static final String SEARCH_SUBHEADER = "Search:";
115 static final String DISPLAY_SUBHEADER = "Display:";
116 static final String SEARCH_TERMS_ONLY_LABEL = "Words";
117 static final String SEARCH_REGEX_LABEL = "Regex";
118 static final String SEARCH_CASE_SENSITIVE_LABEL = "Match Case";
119 static final String INVERSE_SEARCH_RESULT_LABEL = "Inverse";
120 static final String COLOR_BY_TAXONOMIC_GROUP = "Colorize by Taxonomic Group";
121 static final String DISPLAY_SCALE_LABEL = "Scale";
122 static final String NON_LINED_UP_CLADOGRAMS_LABEL = "Non-Lined Up Cladogram";
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 = "Lined Up Cladogram";
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;
180 JMenuItem _write_to_eps_item;
182 JMenuItem _midpoint_root_item;
183 JMenuItem _taxcolor_item;
184 JMenuItem _confcolor_item;
185 JMenuItem _color_rank_jmi;
186 JMenuItem _collapse_species_specific_subtrees;
188 JMenuItem _obtain_detailed_taxonomic_information_jmi;
189 JMenuItem _obtain_detailed_taxonomic_information_deleting_jmi;
190 JMenuItem _obtain_seq_information_jmi;
191 JMenuItem _move_node_names_to_tax_sn_jmi;
192 JMenuItem _move_node_names_to_seq_names_jmi;
193 JMenuItem _extract_tax_code_from_node_names_jmi;
194 JMenuItem _annotate_item;
195 JMenuItem _remove_branch_color_item;
196 JMenuItem _remove_visual_styles_item;
197 JMenuItem _delete_selected_nodes_item;
198 JMenuItem _delete_not_selected_nodes_item;
200 JMenuItem _super_tiny_fonts_item;
201 JMenuItem _tiny_fonts_item;
202 JMenuItem _small_fonts_item;
203 JMenuItem _medium_fonts_item;
204 JMenuItem _large_fonts_item;
206 // _ screen and print
207 JMenuItem _choose_font_mi;
208 JMenuItem _switch_colors_mi;
209 JCheckBoxMenuItem _label_direction_cbmi;
211 JCheckBoxMenuItem _screen_antialias_cbmi;
212 JCheckBoxMenuItem _background_gradient_cbmi;
213 JRadioButtonMenuItem _non_lined_up_cladograms_rbmi;
214 JRadioButtonMenuItem _ext_node_dependent_cladogram_rbmi;
215 JCheckBoxMenuItem _color_by_taxonomic_group_cbmi;
216 JCheckBoxMenuItem _show_scale_cbmi; //TODO fix me
217 JCheckBoxMenuItem _show_overview_cbmi;
218 JCheckBoxMenuItem _show_domain_labels;
219 JCheckBoxMenuItem _show_annotation_ref_source;
220 JCheckBoxMenuItem _abbreviate_scientific_names;
221 JCheckBoxMenuItem _color_labels_same_as_parent_branch;
222 JMenuItem _overview_placment_mi;
223 JMenuItem _choose_minimal_confidence_mi;
224 JCheckBoxMenuItem _show_default_node_shapes_internal_cbmi;
225 JCheckBoxMenuItem _show_default_node_shapes_external_cbmi;
226 JCheckBoxMenuItem _show_default_node_shapes_for_marked_cbmi;
227 JMenuItem _cycle_node_shape_mi;
228 JMenuItem _cycle_node_fill_mi;
229 JMenuItem _choose_node_size_mi;
230 JMenuItem _cycle_data_return;
231 JCheckBoxMenuItem _show_confidence_stddev_cbmi;
232 JCheckBoxMenuItem _right_line_up_domains_cbmi;
233 JCheckBoxMenuItem _line_up_renderable_data_cbmi;
234 JCheckBoxMenuItem _collapsed_with_average_height_cbmi;
235 JCheckBoxMenuItem _show_abbreviated_labels_for_collapsed_nodes_cbmi;
237 JCheckBoxMenuItem _graphics_export_visible_only_cbmi;
238 JCheckBoxMenuItem _antialias_print_cbmi;
239 JCheckBoxMenuItem _print_black_and_white_cbmi;
240 //JMenuItem _print_size_mi;
241 JMenuItem _choose_pdf_width_mi;
243 JCheckBoxMenuItem _internal_number_are_confidence_for_nh_parsing_cbmi;
244 JRadioButtonMenuItem _extract_taxonomy_no_rbmi;
245 JRadioButtonMenuItem _extract_taxonomy_agressive_rbmi;
246 JRadioButtonMenuItem _extract_taxonomy_pfam_strict_rbmi;
247 JRadioButtonMenuItem _extract_taxonomy_pfam_relaxed_rbmi;
248 JCheckBoxMenuItem _replace_underscores_cbmi;
249 JCheckBoxMenuItem _allow_errors_in_distance_to_parent_cbmi;
250 JCheckBoxMenuItem _use_brackets_for_conf_in_nh_export_cbmi;
251 JCheckBoxMenuItem _use_internal_names_for_conf_in_nh_export_cbmi;
252 JCheckBoxMenuItem _parse_beast_style_extended_nexus_tags_cbmi;
254 JCheckBoxMenuItem _search_case_senstive_cbmi;
255 JCheckBoxMenuItem _search_whole_words_only_cbmi;
256 JCheckBoxMenuItem _inverse_search_result_cbmi;
257 JCheckBoxMenuItem _search_with_regex_cbmi;
258 JCheckBoxMenuItem _color_all_found_nodes_when_coloring_subtree_cbmi;
261 JCheckBoxMenuItem _rectangular_type_cbmi;
262 JCheckBoxMenuItem _triangular_type_cbmi;
263 JCheckBoxMenuItem _curved_type_cbmi;
264 JCheckBoxMenuItem _convex_type_cbmi;
265 JCheckBoxMenuItem _euro_type_cbmi;
266 JCheckBoxMenuItem _rounded_type_cbmi;
267 JCheckBoxMenuItem _unrooted_type_cbmi;
268 JCheckBoxMenuItem _circular_type_cbmi;
269 // view as text menu:
270 JMenuItem _view_as_NH_item;
271 JMenuItem _view_as_XML_item;
272 JMenuItem _view_as_nexus_item;
273 JMenuItem _display_basic_information_item;
275 JMenuItem _about_item;
276 JMenuItem _help_item;
277 JMenuItem _website_item;
278 JMenuItem _aptxjs_website_item;
279 JMenuItem _mailing_list_item;
280 JMenuItem _phyloxml_website_item;
281 JMenuItem _phyloxml_ref_item;
282 JMenuItem _aptx_ref_item;
285 JFileChooser _writetopdf_filechooser;
286 JFileChooser _save_filechooser;
287 JFileChooser _writetographics_filechooser;
290 MainPanel _mainpanel;
291 Container _contentpane;
292 final LinkedList<TextFrame> _textframes = new LinkedList<TextFrame>(); ;
293 Configuration _configuration;
295 private Phylogeny _species_tree;
296 InferenceManager _inference_manager;
297 final ProcessPool _process_pool;
298 private String _previous_node_annotation_ref;
301 _process_pool = ProcessPool.createInstance();
302 _writetopdf_filechooser = new JFileChooser();
303 _writetopdf_filechooser.setMultiSelectionEnabled( false );
304 _writetopdf_filechooser.addChoosableFileFilter( pdffilter );
305 _writetographics_filechooser = new JFileChooser();
306 _writetographics_filechooser.setMultiSelectionEnabled( false );
307 _writetographics_filechooser.addChoosableFileFilter( graphicsfilefilter );
308 _save_filechooser = new JFileChooser();
309 _save_filechooser.setMultiSelectionEnabled( false );
310 _save_filechooser.setFileFilter( xmlfilter );
311 _save_filechooser.addChoosableFileFilter( nhfilter );
312 _save_filechooser.addChoosableFileFilter( nexusfilter );
313 _save_filechooser.addChoosableFileFilter( _save_filechooser.getAcceptAllFileFilter() );
315 final String home_dir = System.getProperty( "user.home" );
316 _save_filechooser.setCurrentDirectory( new File( home_dir ) );
317 _writetopdf_filechooser.setCurrentDirectory( new File( home_dir ) );
318 _writetographics_filechooser.setCurrentDirectory( new File( home_dir ) );
320 catch ( final Exception e ) {
322 // Do nothing. Not important.
330 public void actionPerformed( final ActionEvent e ) {
331 final Object o = e.getSource();
333 if ( o == _exit_item ) {
336 else if ( o == _gsdi_item ) {
337 if ( isSubtreeDisplayed() ) {
342 else if ( o == _gsdir_item ) {
343 if ( isSubtreeDisplayed() ) {
348 else if ( o == _taxcolor_item ) {
351 else if ( o == _confcolor_item ) {
354 else if ( o == _color_rank_jmi ) {
357 else if ( o == _collapse_species_specific_subtrees ) {
358 if ( isSubtreeDisplayed() ) {
361 if ( getCurrentTreePanel() != null ) {
362 getCurrentTreePanel().collapseSpeciesSpecificSubtrees();
365 else if ( o == _remove_branch_color_item ) {
366 if ( isSubtreeDisplayed() ) {
369 removeBranchColors();
371 else if ( o == _remove_visual_styles_item ) {
372 if ( isSubtreeDisplayed() ) {
375 removeVisualStyles();
377 else if ( o == _midpoint_root_item ) {
378 if ( isSubtreeDisplayed() ) {
383 else if ( o == _delete_selected_nodes_item ) {
384 if ( isSubtreeDisplayed() ) {
387 deleteSelectedNodes( true );
389 else if ( o == _delete_not_selected_nodes_item ) {
390 if ( isSubtreeDisplayed() ) {
393 deleteSelectedNodes( false );
395 else if ( o == _annotate_item ) {
398 else if ( o == _switch_colors_mi ) {
401 else if ( o == _display_basic_information_item ) {
402 if ( getCurrentTreePanel() != null ) {
403 displayBasicInformation( getCurrentTreePanel().getTreeFile() );
406 else if ( o == _view_as_NH_item ) {
409 else if ( o == _view_as_XML_item ) {
412 else if ( o == _view_as_nexus_item ) {
415 else if ( o == _super_tiny_fonts_item ) {
416 if ( getCurrentTreePanel() != null ) {
417 getCurrentTreePanel().setSuperTinyFonts();
418 getCurrentTreePanel().repaint();
421 else if ( o == _tiny_fonts_item ) {
422 if ( getCurrentTreePanel() != null ) {
423 getCurrentTreePanel().setTinyFonts();
424 getCurrentTreePanel().repaint();
427 else if ( o == _small_fonts_item ) {
428 if ( getCurrentTreePanel() != null ) {
429 getCurrentTreePanel().setSmallFonts();
430 getCurrentTreePanel().repaint();
433 else if ( o == _medium_fonts_item ) {
434 if ( getCurrentTreePanel() != null ) {
435 getCurrentTreePanel().setMediumFonts();
436 getCurrentTreePanel().repaint();
439 else if ( o == _large_fonts_item ) {
440 if ( getCurrentTreePanel() != null ) {
441 getCurrentTreePanel().setLargeFonts();
442 getCurrentTreePanel().repaint();
445 else if ( o == _choose_font_mi ) {
448 else if ( o == _choose_minimal_confidence_mi ) {
449 chooseMinimalConfidence();
451 else if ( o == _choose_node_size_mi ) {
452 chooseNodeSize( getOptions(), this );
454 else if ( o == _overview_placment_mi ) {
455 MainFrame.cycleOverview( getOptions(), getCurrentTreePanel() );
457 else if ( o == _cycle_node_fill_mi ) {
458 MainFrame.cycleNodeFill( getOptions() );
460 else if ( o == _cycle_node_shape_mi ) {
461 MainFrame.cycleNodeShape( getOptions() );
463 else if ( o == _cycle_data_return ) {
464 MainFrame.cycleNodeDataReturn( getOptions(), getConfiguration() );
466 else if ( o == _screen_antialias_cbmi ) {
467 updateOptions( getOptions() );
468 updateScreenTextAntialias( getMainPanel().getTreePanels() );
470 else if ( o == _background_gradient_cbmi ) {
471 updateOptions( getOptions() );
473 else if ( o == _show_domain_labels ) {
474 updateOptions( getOptions() );
476 else if ( o == _show_annotation_ref_source ) {
477 updateOptions( getOptions() );
479 else if ( o == _abbreviate_scientific_names ) {
480 updateOptions( getOptions() );
482 else if ( o == _color_labels_same_as_parent_branch ) {
483 updateOptions( getOptions() );
485 else if ( o == _show_default_node_shapes_internal_cbmi ) {
486 updateOptions( getOptions() );
488 else if ( o == _show_default_node_shapes_external_cbmi ) {
489 updateOptions( getOptions() );
491 else if ( o == _show_default_node_shapes_for_marked_cbmi ) {
492 updateOptions( getOptions() );
494 else if ( o == _non_lined_up_cladograms_rbmi ) {
495 updateOptions( getOptions() );
498 else if ( o == _ext_node_dependent_cladogram_rbmi ) {
499 updateOptions( getOptions() );
502 else if ( o == _search_case_senstive_cbmi ) {
503 if ( ( _search_with_regex_cbmi != null ) && _search_case_senstive_cbmi.isSelected() ) {
504 _search_with_regex_cbmi.setSelected( false );
506 updateOptions( getOptions() );
507 getMainPanel().getControlPanel().search0();
508 getMainPanel().getControlPanel().search1();
510 else if ( o == _search_whole_words_only_cbmi ) {
511 if ( ( _search_with_regex_cbmi != null ) && _search_whole_words_only_cbmi.isSelected() ) {
512 _search_with_regex_cbmi.setSelected( false );
514 updateOptions( getOptions() );
515 getMainPanel().getControlPanel().search0();
516 getMainPanel().getControlPanel().search1();
518 else if ( o == _inverse_search_result_cbmi ) {
519 updateOptions( getOptions() );
520 getMainPanel().getControlPanel().search0();
521 getMainPanel().getControlPanel().search1();
523 else if ( o == _search_with_regex_cbmi ) {
524 if ( ( _search_whole_words_only_cbmi != null ) && _search_with_regex_cbmi.isSelected() ) {
525 _search_whole_words_only_cbmi.setSelected( false );
527 if ( ( _search_case_senstive_cbmi != null ) && _search_with_regex_cbmi.isSelected() ) {
528 _search_case_senstive_cbmi.setSelected( false );
530 updateOptions( getOptions() );
531 getMainPanel().getControlPanel().search0();
532 getMainPanel().getControlPanel().search1();
534 else if ( o == _color_all_found_nodes_when_coloring_subtree_cbmi ) {
535 updateOptions( getOptions() );
537 else if ( o == _parse_beast_style_extended_nexus_tags_cbmi ) {
538 updateOptions( getOptions() );
540 else if ( o == _show_scale_cbmi ) {
541 updateOptions( getOptions() );
543 else if ( o == _color_by_taxonomic_group_cbmi ) {
544 updateOptions( getOptions() );
546 else if ( o == _show_confidence_stddev_cbmi ) {
547 updateOptions( getOptions() );
549 else if ( o == _use_brackets_for_conf_in_nh_export_cbmi ) {
550 if ( _use_brackets_for_conf_in_nh_export_cbmi.isSelected() ) {
551 _use_internal_names_for_conf_in_nh_export_cbmi.setSelected( false );
553 updateOptions( getOptions() );
555 else if ( o == _use_internal_names_for_conf_in_nh_export_cbmi ) {
556 if ( _use_internal_names_for_conf_in_nh_export_cbmi.isSelected() ) {
557 _use_brackets_for_conf_in_nh_export_cbmi.setSelected( false );
559 updateOptions( getOptions() );
561 else if ( o == _label_direction_cbmi ) {
562 updateOptions( getOptions() );
564 else if ( o == _show_overview_cbmi ) {
565 updateOptions( getOptions() );
566 if ( getCurrentTreePanel() != null ) {
567 getCurrentTreePanel().updateOvSizes();
570 else if ( o == _line_up_renderable_data_cbmi ) {
571 if ( !_line_up_renderable_data_cbmi.isSelected() ) {
572 _right_line_up_domains_cbmi.setSelected( false );
574 updateOptions( getOptions() );
577 else if ( o == _collapsed_with_average_height_cbmi ) {
578 if ( _collapsed_with_average_height_cbmi.isSelected() ) {
579 _collapsed_with_average_height_cbmi.setSelected( true );
581 updateOptions( getOptions() );
583 else if ( o == _show_abbreviated_labels_for_collapsed_nodes_cbmi ) {
584 if ( _show_abbreviated_labels_for_collapsed_nodes_cbmi.isSelected() ) {
585 _show_abbreviated_labels_for_collapsed_nodes_cbmi.setSelected( true );
587 updateOptions( getOptions() );
589 else if ( o == _right_line_up_domains_cbmi ) {
590 if ( _right_line_up_domains_cbmi.isSelected() ) {
591 _line_up_renderable_data_cbmi.setSelected( true );
593 updateOptions( getOptions() );
595 else if ( ( o == _rectangular_type_cbmi ) || ( o == _triangular_type_cbmi ) || ( o == _curved_type_cbmi )
596 || ( o == _convex_type_cbmi ) || ( o == _euro_type_cbmi ) || ( o == _rounded_type_cbmi )
597 || ( o == _unrooted_type_cbmi ) || ( o == _circular_type_cbmi ) ) {
600 else if ( o == _about_item ) {
603 else if ( o == _help_item ) {
605 AptxUtil.openWebsite( AptxConstants.APTX_DOC_SITE );
607 catch ( final IOException e1 ) {
608 ForesterUtil.printErrorMessage( AptxConstants.PRG_NAME, e1.toString() );
611 else if ( o == _website_item ) {
613 AptxUtil.openWebsite( AptxConstants.APTX_WEB_SITE);
615 catch ( final IOException e1 ) {
616 ForesterUtil.printErrorMessage( AptxConstants.PRG_NAME, e1.toString() );
619 else if ( o == _aptxjs_website_item ) {
621 AptxUtil.openWebsite( AptxConstants.APTX_JS_WEB_SITE);;
623 catch ( final IOException e1 ) {
624 ForesterUtil.printErrorMessage( AptxConstants.PRG_NAME, e1.toString() );
627 else if ( o == _mailing_list_item ) {
629 AptxUtil.openWebsite( AptxConstants.APTX_MAILING_LIST );
631 catch ( final IOException e1 ) {
632 ForesterUtil.printErrorMessage( AptxConstants.PRG_NAME, e1.toString() );
635 else if ( o == _phyloxml_website_item ) {
637 AptxUtil.openWebsite( AptxConstants.PHYLOXML_WEB_SITE );
639 catch ( final IOException e1 ) {
640 ForesterUtil.printErrorMessage( AptxConstants.PRG_NAME, e1.toString() );
643 else if ( o == _aptx_ref_item ) {
645 AptxUtil.openWebsite( AptxConstants.APTX_REFERENCE_URL );
647 catch ( final IOException e1 ) {
648 ForesterUtil.printErrorMessage( AptxConstants.PRG_NAME, e1.toString() );
651 else if ( o == _phyloxml_ref_item ) {
653 AptxUtil.openWebsite( AptxConstants.PHYLOXML_REFERENCE_URL );
655 catch ( final IOException e1 ) {
656 ForesterUtil.printErrorMessage( AptxConstants.PRG_NAME, e1.toString() );
659 else if ( o == _write_to_pdf_item ) {
660 final File curr_dir = writeToPdf( _mainpanel.getCurrentPhylogeny(),
662 _writetopdf_filechooser,
666 if ( curr_dir != null ) {
667 setCurrentDir( curr_dir );
670 else if ( o == _save_all_item ) {
673 else if ( o == _write_to_jpg_item ) {
674 final File new_dir = writeToGraphicsFile( _mainpanel.getCurrentPhylogeny(),
675 GraphicsExportType.JPG,
677 _writetographics_filechooser,
681 if ( new_dir != null ) {
682 setCurrentDir( new_dir );
685 else if ( o == _write_to_gif_item ) {
686 final File new_dir = writeToGraphicsFile( _mainpanel.getCurrentPhylogeny(),
687 GraphicsExportType.GIF,
689 _writetographics_filechooser,
693 if ( new_dir != null ) {
694 setCurrentDir( new_dir );
697 else if ( o == _write_to_tif_item ) {
698 final File new_dir = writeToGraphicsFile( _mainpanel.getCurrentPhylogeny(),
699 GraphicsExportType.TIFF,
701 _writetographics_filechooser,
705 if ( new_dir != null ) {
706 setCurrentDir( new_dir );
709 else if ( o == _write_to_bmp_item ) {
710 final File new_dir = writeToGraphicsFile( _mainpanel.getCurrentPhylogeny(),
711 GraphicsExportType.BMP,
713 _writetographics_filechooser,
717 if ( new_dir != null ) {
718 setCurrentDir( new_dir );
721 else if ( o == _write_to_png_item ) {
722 final File new_dir = writeToGraphicsFile( _mainpanel.getCurrentPhylogeny(),
723 GraphicsExportType.PNG,
725 _writetographics_filechooser,
729 if ( new_dir != null ) {
730 setCurrentDir( new_dir );
733 else if (o == _write_to_eps_item) {
734 final File new_dir = writeToGraphicsFile(_mainpanel.getCurrentPhylogeny(),
735 GraphicsExportType.EPS,
737 _writetographics_filechooser,
741 if (new_dir != null) {
742 setCurrentDir(new_dir);
745 else if ( o == _print_item ) {
746 print( getCurrentTreePanel(), getOptions(), this );
748 else if ( o == _save_item ) {
749 final File new_dir = writeToFile( _mainpanel.getCurrentPhylogeny(),
755 if ( new_dir != null ) {
756 setCurrentDir( new_dir );
759 else if ( o == _graphics_export_visible_only_cbmi ) {
760 updateOptions( getOptions() );
762 else if ( o == _antialias_print_cbmi ) {
763 updateOptions( getOptions() );
765 else if ( o == _print_black_and_white_cbmi ) {
766 updateOptions( getOptions() );
768 else if ( o == _choose_pdf_width_mi ) {
771 else if ( o == _lineage_inference ) {
772 if ( isSubtreeDisplayed() ) {
773 JOptionPane.showMessageDialog( this,
775 "Cannot infer ancestral taxonomies",
776 JOptionPane.ERROR_MESSAGE );
779 executeLineageInference();
782 if ( _load_phylogeny_from_webservice_menu_items != null ) {
783 for( int i = 0; i < _load_phylogeny_from_webservice_menu_items.length; ++i ) {
784 if ( o == _load_phylogeny_from_webservice_menu_items[ i ] ) {
785 readPhylogeniesFromWebservice( i );
790 _contentpane.repaint();
793 public Configuration getConfiguration() {
794 return _configuration;
798 * This method returns the current external node data which
799 * has been selected by the user by clicking the "Return ..."
800 * menu item. This method is expected to be called from Javascript or
803 * @return current external node data as String
805 public String getCurrentExternalNodesDataBuffer() {
806 return getCurrentTreePanel().getCurrentExternalNodesDataBufferAsString();
809 public int getCurrentExternalNodesDataBufferChangeCounter() {
810 return getCurrentTreePanel().getCurrentExternalNodesDataBufferChangeCounter();
813 public int getCurrentExternalNodesDataBufferLength() {
814 return getCurrentTreePanel().getCurrentExternalNodesDataBufferAsString().length();
817 public InferenceManager getInferenceManager() {
818 return _inference_manager;
821 public MainPanel getMainPanel() {
825 public Options getOptions() {
829 public ProcessPool getProcessPool() {
830 return _process_pool;
833 public void showTextFrame( final String s, final String title ) {
835 _textframes.addLast( TextFrame.instantiate( s, title, _textframes ) );
838 public void showWhole() {
839 _mainpanel.getControlPanel().showWhole();
842 public void updateProcessMenu() {
843 // In general Swing is not thread safe.
844 // See "Swing's Threading Policy".
845 SwingUtilities.invokeLater( new Runnable() {
849 doUpdateProcessMenu();
854 private void annotateSequences() {
855 if ( getCurrentTreePanel() != null ) {
856 List<PhylogenyNode> nodes = null;
857 if ( ( getCurrentTreePanel().getFoundNodes0() != null )
858 || ( getCurrentTreePanel().getFoundNodes1() != null ) ) {
859 nodes = getCurrentTreePanel().getFoundNodesAsListOfPhylogenyNodes();
861 if ( ( nodes == null ) || nodes.isEmpty() ) {
863 .showMessageDialog( this,
864 "Need to select nodes, either via direct selection or via the \"Search\" function",
865 "No nodes selected for annotation",
866 JOptionPane.ERROR_MESSAGE );
869 final Phylogeny phy = getMainPanel().getCurrentPhylogeny();
870 if ( ( phy != null ) && !phy.isEmpty() ) {
871 final JTextField ref_field = new JTextField( 10 );
872 final JTextField desc_filed = new JTextField( 20 );
873 ref_field.setText( ForesterUtil.isEmpty( getPreviousNodeAnnotationReference() ) ? ""
874 : getPreviousNodeAnnotationReference() );
875 final JPanel my_panel = new JPanel();
876 my_panel.add( new JLabel( "Reference " ) );
877 my_panel.add( ref_field );
878 my_panel.add( Box.createHorizontalStrut( 15 ) );
879 my_panel.add( new JLabel( "Description " ) );
880 my_panel.add( desc_filed );
881 final int result = JOptionPane.showConfirmDialog( null,
883 "Enter the sequence annotation(s) for the "
884 + nodes.size() + " selected nodes",
885 JOptionPane.OK_CANCEL_OPTION );
886 if ( result == JOptionPane.OK_OPTION ) {
887 String ref = ref_field.getText();
888 String desc = desc_filed.getText();
889 if ( !ForesterUtil.isEmpty( ref ) ) {
891 ref = ref.replaceAll( "\\s+", " " );
892 if ( ( ref.indexOf( ':' ) < 1 ) || ( ref.indexOf( ':' ) > ( ref.length() - 2 ) )
893 || ( ref.length() < 3 ) ) {
894 JOptionPane.showMessageDialog( this,
895 "Reference needs to be in the form of \"GO:1234567\"",
896 "Illegal Format for Annotation Reference",
897 JOptionPane.ERROR_MESSAGE );
902 setPreviousNodeAnnotationReference( ref );
904 if ( desc != null ) {
906 desc = desc.replaceAll( "\\s+", " " );
908 if ( !ForesterUtil.isEmpty( ref ) || !ForesterUtil.isEmpty( desc ) ) {
909 for( final PhylogenyNode n : nodes ) {
910 ForesterUtil.ensurePresenceOfSequence( n );
911 final Annotation ann = ForesterUtil.isEmpty( ref ) ? new Annotation()
912 : new Annotation( ref );
913 if ( !ForesterUtil.isEmpty( desc ) ) {
916 n.getNodeData().getSequence().addAnnotation( ann );
919 getMainPanel().getControlPanel().showAnnotations();
925 private void chooseFont() {
926 final FontChooser fc = new FontChooser();
927 fc.setFont( getMainPanel().getTreeFontSet().getLargeFont() );
928 fc.showDialog( this, "Select the Base Font" );
929 getMainPanel().getTreeFontSet().setBaseFont( fc.getFont() );
930 getControlPanel().displayedPhylogenyMightHaveChanged( true );
931 if ( getMainPanel().getCurrentTreePanel() != null ) {
932 getMainPanel().getCurrentTreePanel().resetPreferredSize();
933 getMainPanel().getCurrentTreePanel().updateOvSizes();
939 private void chooseMinimalConfidence() {
940 final String s = ( String ) JOptionPane
941 .showInputDialog( this,
942 "Please enter the minimum for confidence values to be displayed.\n"
943 + "[current value: " + getOptions().getMinConfidenceValue() + "]\n",
944 "Minimal Confidence Value",
945 JOptionPane.QUESTION_MESSAGE,
948 getOptions().getMinConfidenceValue() );
949 if ( !ForesterUtil.isEmpty( s ) ) {
950 boolean success = true;
952 final String m_str = s.trim();
953 if ( !ForesterUtil.isEmpty( m_str ) ) {
955 m = Double.parseDouble( m_str );
957 catch ( final Exception ex ) {
964 if ( success && ( m >= 0.0 ) ) {
965 getOptions().setMinConfidenceValue( m );
970 private void deleteSelectedNodes( final boolean delete ) {
971 final Phylogeny phy = getMainPanel().getCurrentPhylogeny();
972 if ( ( phy == null ) || ( phy.getNumberOfExternalNodes() < 2 ) ) {
975 final List<PhylogenyNode> nodes = new ArrayList<PhylogenyNode>();
976 if ( ( getCurrentTreePanel().getFoundNodes0() != null ) || ( getCurrentTreePanel().getFoundNodes1() != null ) ) {
977 final List<PhylogenyNode> all_selected_nodes = getCurrentTreePanel().getFoundNodesAsListOfPhylogenyNodes();
978 for( final PhylogenyNode n : all_selected_nodes ) {
979 if ( n.isExternal() ) {
984 String function = "Retain";
988 if ( ( nodes == null ) || nodes.isEmpty() ) {
990 .showMessageDialog( this,
991 "Need to select external nodes, either via direct selection or via the \"Search\" function",
992 "No external nodes selected to " + function.toLowerCase(),
993 JOptionPane.ERROR_MESSAGE );
996 final int todo = nodes.size();
997 final int ext = phy.getNumberOfExternalNodes();
1003 JOptionPane.showMessageDialog( this,
1004 "Cannot delete all nodes",
1005 "Attempt to delete all nodes ",
1006 JOptionPane.ERROR_MESSAGE );
1009 final int result = JOptionPane.showConfirmDialog( null, function + " " + todo
1010 + " external node(s), from a total of " + ext + " external nodes," + "\nresulting in tree with " + res
1011 + " nodes?", function + " external nodes", JOptionPane.OK_CANCEL_OPTION );
1012 if ( result == JOptionPane.OK_OPTION ) {
1014 final List<PhylogenyNode> to_delete = new ArrayList<PhylogenyNode>();
1015 for( final PhylogenyNodeIterator it = phy.iteratorExternalForward(); it.hasNext(); ) {
1016 final PhylogenyNode n = it.next();
1017 if ( !nodes.contains( n ) ) {
1021 for( final PhylogenyNode n : to_delete ) {
1022 phy.deleteSubtree( n, true );
1026 for( final PhylogenyNode n : nodes ) {
1027 phy.deleteSubtree( n, true );
1031 getCurrentTreePanel().setNodeInPreorderToNull();
1032 phy.externalNodesHaveChanged();
1033 phy.clearHashIdToNodeMap();
1034 phy.recalculateNumberOfExternalDescendants( true );
1035 getCurrentTreePanel().resetNodeIdToDistToLeafMap();
1036 getCurrentTreePanel().setEdited( true );
1041 private void doUpdateProcessMenu() {
1042 if ( _process_pool.size() > 0 ) {
1043 if ( _process_menu == null ) {
1044 _process_menu = createMenu( "", getConfiguration() );
1045 _process_menu.setForeground( Color.RED );
1047 _process_menu.removeAll();
1048 final String text = "Processes Running: " + _process_pool.size();
1049 _process_menu.setText( text );
1050 _jmenubar.add( _process_menu );
1051 for( int i = 0; i < _process_pool.size(); ++i ) {
1052 final ProcessRunning p = _process_pool.getProcessByIndex( i );
1053 _process_menu.add( customizeJMenuItem( new JMenuItem( p.getName() + " [" + p.getStart() + "]" ) ) );
1057 if ( _process_menu != null ) {
1058 _process_menu.removeAll();
1059 _jmenubar.remove( _process_menu );
1062 _jmenubar.validate();
1063 _jmenubar.repaint();
1067 private String getPreviousNodeAnnotationReference() {
1068 return _previous_node_annotation_ref;
1071 private void removeBranchColors() {
1072 if ( getMainPanel().getCurrentPhylogeny() != null ) {
1073 AptxUtil.removeBranchColors( getMainPanel().getCurrentPhylogeny() );
1077 private void removeVisualStyles() {
1078 if ( getMainPanel().getCurrentPhylogeny() != null ) {
1079 AptxUtil.removeVisualStyles( getMainPanel().getCurrentPhylogeny() );
1083 private void setPreviousNodeAnnotationReference( final String previous_node_annotation_ref ) {
1084 _previous_node_annotation_ref = previous_node_annotation_ref;
1087 private void writeAllToFile() {
1088 if ( ( getMainPanel().getTabbedPane() == null ) || ( getMainPanel().getTabbedPane().getTabCount() < 1 ) ) {
1091 final File my_dir = getCurrentDir();
1092 if ( my_dir != null ) {
1093 _save_filechooser.setCurrentDirectory( my_dir );
1095 _save_filechooser.setSelectedFile( new File( "" ) );
1096 final int result = _save_filechooser.showSaveDialog( _contentpane );
1097 final File file = _save_filechooser.getSelectedFile();
1098 setCurrentDir( _save_filechooser.getCurrentDirectory() );
1099 if ( ( file != null ) && ( result == JFileChooser.APPROVE_OPTION ) ) {
1100 if ( file.exists() ) {
1101 final int i = JOptionPane.showConfirmDialog( this,
1102 file + " already exists. Overwrite?",
1104 JOptionPane.OK_CANCEL_OPTION,
1105 JOptionPane.WARNING_MESSAGE );
1106 if ( i != JOptionPane.OK_OPTION ) {
1113 catch ( final Exception e ) {
1114 JOptionPane.showMessageDialog( this,
1115 "Failed to delete: " + file,
1117 JOptionPane.WARNING_MESSAGE );
1121 final int count = getMainPanel().getTabbedPane().getTabCount();
1122 final List<Phylogeny> trees = new ArrayList<Phylogeny>();
1123 for( int i = 0; i < count; ++i ) {
1124 final Phylogeny phy = getMainPanel().getPhylogeny( i );
1125 if ( ForesterUtil.isEmpty( phy.getName() )
1126 && !ForesterUtil.isEmpty( getMainPanel().getTabbedPane().getTitleAt( i ) ) ) {
1127 phy.setName( getMainPanel().getTabbedPane().getTitleAt( i ) );
1130 getMainPanel().getTreePanels().get( i ).setEdited( false );
1132 final PhylogenyWriter writer = new PhylogenyWriter();
1134 writer.toPhyloXML( file, trees, 0, ForesterUtil.LINE_SEPARATOR );
1136 catch ( final IOException e ) {
1137 JOptionPane.showMessageDialog( this,
1138 "Failed to write to: " + file,
1140 JOptionPane.WARNING_MESSAGE );
1145 public void activateSaveAllIfNeeded() {
1146 if ( ( getMainPanel().getTabbedPane() != null ) && ( getMainPanel().getTabbedPane().getTabCount() > 1 ) ) {
1147 _save_all_item.setEnabled( true );
1150 _save_all_item.setEnabled( false );
1154 void buildFileMenu() {
1155 // _file_jmenu = MainFrame.createMenu( "File", getConfiguration() );
1156 // _file_jmenu.add( _save_item = new JMenuItem( "Save Tree As..." ) );
1157 // _file_jmenu.addSeparator();
1158 // _file_jmenu.add( _write_to_pdf_item = new JMenuItem( "Export to PDF file ..." ) );
1159 // if ( AptxUtil.canWriteFormat( "tif" ) || AptxUtil.canWriteFormat( "tiff" ) || AptxUtil.canWriteFormat( "TIF" ) ) {
1160 // _file_jmenu.add( _write_to_tif_item = new JMenuItem( "Export to TIFF file..." ) );
1162 // _file_jmenu.add( _write_to_png_item = new JMenuItem( "Export to PNG file..." ) );
1163 // _file_jmenu.add( _write_to_jpg_item = new JMenuItem( "Export to JPG file..." ) );
1164 // if ( AptxUtil.canWriteFormat( "gif" ) ) {
1165 // _file_jmenu.add( _write_to_gif_item = new JMenuItem( "Export to GIF file..." ) );
1167 // if ( AptxUtil.canWriteFormat( "bmp" ) ) {
1168 // _file_jmenu.add( _write_to_bmp_item = new JMenuItem( "Export to BMP file..." ) );
1171 // _file_jmenu.add( _write_to_eps_item = new JMenuItem("Export to EPS file...") );
1173 // _file_jmenu.addSeparator();
1174 // _file_jmenu.add( _print_item = new JMenuItem( "Print..." ) );
1175 // _file_jmenu.addSeparator();
1176 // _file_jmenu.add( _exit_item = new JMenuItem( "Exit" ) );
1177 // customizeJMenuItem( _save_item );
1178 // customizeJMenuItem( _write_to_pdf_item );
1179 // customizeJMenuItem( _write_to_png_item );
1180 // customizeJMenuItem( _write_to_jpg_item );
1181 // customizeJMenuItem( _write_to_gif_item );
1182 // customizeJMenuItem( _write_to_tif_item );
1183 // customizeJMenuItem( _write_to_bmp_item );
1184 // customizeJMenuItem(_write_to_eps_item);
1185 // customizeJMenuItem( _print_item );
1186 // customizeJMenuItem( _exit_item );
1187 // _jmenubar.add( _file_jmenu );
1190 void buildFontSizeMenu() {
1191 _font_size_menu = createMenu( FONT_SIZE_MENU_LABEL, getConfiguration() );
1192 _font_size_menu.add( _super_tiny_fonts_item = new JMenuItem( "Super Tiny Fonts" ) );
1193 _font_size_menu.add( _tiny_fonts_item = new JMenuItem( "Tiny Fonts" ) );
1194 _font_size_menu.add( _small_fonts_item = new JMenuItem( "Small Fonts" ) );
1195 _font_size_menu.add( _medium_fonts_item = new JMenuItem( "Medium Fonts" ) );
1196 _font_size_menu.add( _large_fonts_item = new JMenuItem( "Large Fonts" ) );
1197 customizeJMenuItem( _super_tiny_fonts_item );
1198 customizeJMenuItem( _tiny_fonts_item );
1199 customizeJMenuItem( _small_fonts_item );
1200 customizeJMenuItem( _medium_fonts_item );
1201 customizeJMenuItem( _large_fonts_item );
1202 _jmenubar.add( _font_size_menu );
1205 void buildHelpMenu() {
1206 _help_jmenu = createMenu( "Help", getConfiguration() );
1207 _help_jmenu.add( _help_item = new JMenuItem( "Documentation" ) );
1208 _help_jmenu.addSeparator();
1209 _help_jmenu.add( _website_item = new JMenuItem( "Archaeopteryx Home" ) );
1210 _help_jmenu.add( _aptxjs_website_item = new JMenuItem( "NEW! Archaeopteryx online version: Archaeopteryx.js" ) );
1211 _help_jmenu.add( _mailing_list_item = new JMenuItem( "Mailing List" ) );
1212 _aptx_ref_item = new JMenuItem( "Archaeopteryx Reference" ); //TODO need to add this...
1213 _help_jmenu.add( _phyloxml_website_item = new JMenuItem( "phyloXML Home" ) );
1214 _help_jmenu.add( _phyloxml_ref_item = new JMenuItem( "phyloXML Reference" ) );
1215 _help_jmenu.addSeparator();
1216 _help_jmenu.add( _about_item = new JMenuItem( "About" ) );
1217 customizeJMenuItem( _help_item );
1218 customizeJMenuItem( _website_item );
1219 customizeJMenuItem( _aptxjs_website_item );
1220 customizeJMenuItem( _mailing_list_item );
1221 customizeJMenuItem( _phyloxml_website_item );
1222 customizeJMenuItem( _aptx_ref_item );
1223 customizeJMenuItem( _phyloxml_ref_item );
1224 customizeJMenuItem( _about_item );
1225 _phyloxml_ref_item.setToolTipText( PHYLOXML_REF_TOOL_TIP );
1226 _aptx_ref_item.setToolTipText( APTX_REF_TOOL_TIP );
1227 _jmenubar.add( _help_jmenu );
1230 void buildTypeMenu() {
1231 _type_menu = createMenu( TYPE_MENU_HEADER, getConfiguration() );
1232 _type_menu.add( _rectangular_type_cbmi = new JCheckBoxMenuItem( MainFrame.RECTANGULAR_TYPE_CBMI_LABEL ) );
1233 _type_menu.add( _euro_type_cbmi = new JCheckBoxMenuItem( MainFrame.EURO_TYPE_CBMI_LABEL ) );
1234 _type_menu.add( _rounded_type_cbmi = new JCheckBoxMenuItem( MainFrame.ROUNDED_TYPE_CBMI_LABEL ) );
1235 _type_menu.add( _curved_type_cbmi = new JCheckBoxMenuItem( MainFrame.CURVED_TYPE_CBMI_LABEL ) );
1236 _type_menu.add( _triangular_type_cbmi = new JCheckBoxMenuItem( MainFrame.TRIANGULAR_TYPE_CBMI_LABEL ) );
1237 _type_menu.add( _convex_type_cbmi = new JCheckBoxMenuItem( MainFrame.CONVEX_TYPE_CBMI_LABEL ) );
1238 _type_menu.add( _unrooted_type_cbmi = new JCheckBoxMenuItem( MainFrame.UNROOTED_TYPE_CBMI_LABEL ) );
1239 _type_menu.add( _circular_type_cbmi = new JCheckBoxMenuItem( MainFrame.CIRCULAR_TYPE_CBMI_LABEL ) );
1240 customizeCheckBoxMenuItem( _rectangular_type_cbmi, false );
1241 customizeCheckBoxMenuItem( _triangular_type_cbmi, false );
1242 customizeCheckBoxMenuItem( _euro_type_cbmi, false );
1243 customizeCheckBoxMenuItem( _rounded_type_cbmi, false );
1244 customizeCheckBoxMenuItem( _curved_type_cbmi, false );
1245 customizeCheckBoxMenuItem( _convex_type_cbmi, false );
1246 customizeCheckBoxMenuItem( _unrooted_type_cbmi, false );
1247 customizeCheckBoxMenuItem( _circular_type_cbmi, false );
1248 _triangular_type_cbmi.setToolTipText( "not suitable for phylograms" );
1249 _curved_type_cbmi.setToolTipText( "not suitable for phylograms" );
1250 _unrooted_type_cbmi.setToolTipText( MainFrame.USE_MOUSEWHEEL_SHIFT_TO_ROTATE );
1251 _circular_type_cbmi.setToolTipText( MainFrame.USE_MOUSEWHEEL_SHIFT_TO_ROTATE );
1252 initializeTypeMenu( getOptions() );
1253 _jmenubar.add( _type_menu );
1256 void buildViewMenu() {
1257 _view_jmenu = createMenu( "View", getConfiguration() );
1258 _view_jmenu.add( _display_basic_information_item = new JMenuItem( SHOW_BASIC_TREE_INFORMATION_LABEL ) );
1259 _view_jmenu.addSeparator();
1260 _view_jmenu.add( _view_as_XML_item = new JMenuItem( "as phyloXML" ) );
1261 _view_jmenu.add( _view_as_NH_item = new JMenuItem( "as Newick" ) );
1262 _view_jmenu.add( _view_as_nexus_item = new JMenuItem( "as Nexus" ) );
1263 customizeJMenuItem( _display_basic_information_item );
1264 customizeJMenuItem( _view_as_NH_item );
1265 customizeJMenuItem( _view_as_XML_item );
1266 customizeJMenuItem( _view_as_nexus_item );
1267 _jmenubar.add( _view_jmenu );
1270 void checkTextFrames() {
1271 if ( _textframes.size() > 5 ) {
1273 if ( _textframes.getFirst() != null ) {
1274 _textframes.getFirst().removeMe();
1277 _textframes.removeFirst();
1280 catch ( final NoSuchElementException e ) {
1286 void choosePdfWidth() {
1287 final String s = ( String ) JOptionPane.showInputDialog( this,
1288 "Please enter the default line width for PDF export.\n"
1289 + "[current value: "
1290 + getOptions().getPrintLineWidth() + "]\n",
1291 "Line Width for PDF Export",
1292 JOptionPane.QUESTION_MESSAGE,
1295 getOptions().getPrintLineWidth() );
1296 if ( !ForesterUtil.isEmpty( s ) ) {
1297 boolean success = true;
1299 final String m_str = s.trim();
1300 if ( !ForesterUtil.isEmpty( m_str ) ) {
1302 f = Float.parseFloat( m_str );
1304 catch ( final Exception ex ) {
1311 if ( success && ( f > 0.0 ) ) {
1312 getOptions().setPrintLineWidth( f );
1318 removeAllTextFrames();
1319 if ( _mainpanel != null ) {
1320 _mainpanel.terminate();
1322 if ( _contentpane != null ) {
1323 _contentpane.removeAll();
1325 setVisible( false );
1330 if ( _mainpanel.getCurrentTreePanel() != null ) {
1331 final Map<String, Integer> present_ranks = AptxUtil.getRankCounts( _mainpanel.getCurrentTreePanel().getPhylogeny());
1332 final String[] ranks = AptxUtil.getAllPossibleRanks(present_ranks);
1333 String rank = ( String ) JOptionPane
1334 .showInputDialog( this,
1335 "What rank should the colorization be based on",
1337 JOptionPane.QUESTION_MESSAGE,
1341 if ( !ForesterUtil.isEmpty( rank ) ) {
1342 if ( rank.indexOf( '(' ) > 0 ) {
1343 rank = rank.substring( 0, rank.indexOf( '(' ) ).trim();
1345 _mainpanel.getCurrentTreePanel().colorRank( rank );
1351 if ( _mainpanel.getCurrentTreePanel() != null ) {
1352 _mainpanel.getCurrentTreePanel().confColor();
1356 void customizeCheckBoxMenuItem( final JCheckBoxMenuItem item, final boolean is_selected ) {
1357 if ( item != null ) {
1358 item.setFont( MainFrame.menu_font );
1359 if ( !getConfiguration().isUseNativeUI() ) {
1360 item.setBackground( getConfiguration().getGuiMenuBackgroundColor() );
1361 item.setForeground( getConfiguration().getGuiMenuTextColor() );
1363 item.setSelected( is_selected );
1364 item.addActionListener( this );
1368 JMenuItem customizeJMenuItem( final JMenuItem jmi ) {
1369 if ( jmi != null ) {
1370 jmi.setFont( MainFrame.menu_font );
1371 if ( !getConfiguration().isUseNativeUI() ) {
1372 jmi.setBackground( getConfiguration().getGuiMenuBackgroundColor() );
1373 jmi.setForeground( getConfiguration().getGuiMenuTextColor() );
1375 jmi.addActionListener( this );
1380 void customizeRadioButtonMenuItem( final JRadioButtonMenuItem item, final boolean is_selected ) {
1381 if ( item != null ) {
1382 item.setFont( MainFrame.menu_font );
1383 if ( !getConfiguration().isUseNativeUI() ) {
1384 item.setBackground( getConfiguration().getGuiMenuBackgroundColor() );
1385 item.setForeground( getConfiguration().getGuiMenuTextColor() );
1387 item.setSelected( is_selected );
1388 item.addActionListener( this );
1392 void displayBasicInformation( final File treefile ) {
1393 if ( ( _mainpanel.getCurrentPhylogeny() != null ) && !_mainpanel.getCurrentPhylogeny().isEmpty() ) {
1394 String title = "Basic Information";
1395 if ( !ForesterUtil.isEmpty( _mainpanel.getCurrentPhylogeny().getName() ) ) {
1396 title = title + " for \"" + _mainpanel.getCurrentPhylogeny().getName() + "\"";
1398 showTextFrame( AptxUtil.createBasicInformation( _mainpanel.getCurrentPhylogeny(), treefile ), title );
1402 void exceptionOccuredDuringOpenFile( final Exception e ) {
1404 _mainpanel.getCurrentTreePanel().setArrowCursor();
1406 catch ( final Exception ex ) {
1409 JOptionPane.showMessageDialog( this,
1410 ForesterUtil.wordWrap( e.getLocalizedMessage(), 80 ),
1411 "Error during File|Open",
1412 JOptionPane.ERROR_MESSAGE );
1415 void executeGSDI() {
1416 if ( !isOKforSDI( false, true ) ) {
1419 if ( !_mainpanel.getCurrentPhylogeny().isRooted() ) {
1420 JOptionPane.showMessageDialog( this,
1421 "Gene tree is not rooted.",
1422 "Cannot execute GSDI",
1423 JOptionPane.ERROR_MESSAGE );
1426 final Phylogeny gene_tree = _mainpanel.getCurrentPhylogeny().copy();
1427 gene_tree.setAllNodesToNotCollapse();
1428 gene_tree.recalculateNumberOfExternalDescendants( false );
1430 final Phylogeny species_tree = getSpeciesTree().copy();
1432 gsdi = new GSDI( gene_tree, species_tree, false, true, true, true );
1434 catch ( final SDIException e ) {
1435 JOptionPane.showMessageDialog( this,
1436 e.getLocalizedMessage(),
1437 "Error during GSDI",
1438 JOptionPane.ERROR_MESSAGE );
1441 catch ( final Exception e ) {
1442 AptxUtil.unexpectedException( e );
1445 gene_tree.setRerootable( false );
1446 gene_tree.clearHashIdToNodeMap();
1447 gene_tree.recalculateNumberOfExternalDescendants( true );
1448 _mainpanel.addPhylogenyInNewTab( gene_tree, getConfiguration(), "gene tree", null );
1449 getMainPanel().getControlPanel().setShowEvents( true );
1451 final int selected = _mainpanel.getTabbedPane().getSelectedIndex();
1452 _mainpanel.addPhylogenyInNewTab( species_tree, getConfiguration(), "species tree", null );
1454 _mainpanel.getTabbedPane().setSelectedIndex( selected );
1456 _mainpanel.getCurrentTreePanel().setEdited( true );
1457 final int poly = PhylogenyMethods.countNumberOfPolytomies( species_tree );
1458 if ( gsdi.getStrippedExternalGeneTreeNodes().size() > 0 ) {
1459 JOptionPane.showMessageDialog( this,
1460 "Duplications: " + gsdi.getDuplicationsSum() + "\n"
1461 + "Potential duplications: "
1462 + gsdi.getSpeciationOrDuplicationEventsSum() + "\n"
1463 + "Speciations: " + gsdi.getSpeciationsSum() + "\n"
1464 + "Stripped gene tree nodes: "
1465 + gsdi.getStrippedExternalGeneTreeNodes().size() + "\n"
1466 + "Taxonomy linkage based on: " + gsdi.getTaxCompBase() + "\n"
1467 + "Number of polytomies in species tree used: " + poly + "\n",
1468 "GSDI successfully completed",
1469 JOptionPane.WARNING_MESSAGE );
1472 JOptionPane.showMessageDialog( this,
1473 "Duplications: " + gsdi.getDuplicationsSum() + "\n"
1474 + "Potential duplications: "
1475 + gsdi.getSpeciationOrDuplicationEventsSum() + "\n"
1476 + "Speciations: " + gsdi.getSpeciationsSum() + "\n"
1477 + "Stripped gene tree nodes: "
1478 + gsdi.getStrippedExternalGeneTreeNodes().size() + "\n"
1479 + "Taxonomy linkage based on: " + gsdi.getTaxCompBase() + "\n"
1480 + "Number of polytomies in species tree used: " + poly + "\n",
1481 "GSDI successfully completed",
1482 JOptionPane.INFORMATION_MESSAGE );
1486 void executeGSDIR() {
1487 if ( !isOKforSDI( false, false ) ) {
1490 final int p = PhylogenyMethods.countNumberOfPolytomies( _mainpanel.getCurrentPhylogeny() );
1492 && !( ( p == 1 ) && ( _mainpanel.getCurrentPhylogeny().getRoot().getNumberOfDescendants() == 3 ) ) ) {
1493 JOptionPane.showMessageDialog( this,
1494 "Gene tree is not completely binary",
1495 "Cannot execute GSDI",
1496 JOptionPane.ERROR_MESSAGE );
1499 final Phylogeny gene_tree = _mainpanel.getCurrentPhylogeny().copy();
1500 gene_tree.setAllNodesToNotCollapse();
1501 gene_tree.recalculateNumberOfExternalDescendants( false );
1503 final Phylogeny species_tree = getSpeciesTree().copy();
1505 gsdir = new GSDIR( gene_tree, species_tree, true, true, true );
1507 catch ( final SDIException e ) {
1508 JOptionPane.showMessageDialog( this,
1509 e.getLocalizedMessage(),
1510 "Error during GSDIR",
1511 JOptionPane.ERROR_MESSAGE );
1514 catch ( final Exception e ) {
1515 AptxUtil.unexpectedException( e );
1518 final Phylogeny result_gene_tree = gsdir.getMinDuplicationsSumGeneTree();
1519 result_gene_tree.setRerootable( false );
1520 result_gene_tree.clearHashIdToNodeMap();
1521 result_gene_tree.recalculateNumberOfExternalDescendants( true );
1522 PhylogenyMethods.orderAppearance( result_gene_tree.getRoot(), true, true, DESCENDANT_SORT_PRIORITY.NODE_NAME );
1523 _mainpanel.addPhylogenyInNewTab( result_gene_tree, getConfiguration(), "gene tree", null );
1524 getMainPanel().getControlPanel().setShowEvents( true );
1526 final int selected = _mainpanel.getTabbedPane().getSelectedIndex();
1527 _mainpanel.addPhylogenyInNewTab( species_tree, getConfiguration(), "species tree", null );
1529 _mainpanel.getTabbedPane().setSelectedIndex( selected );
1531 _mainpanel.getCurrentTreePanel().setEdited( true );
1532 final int poly = PhylogenyMethods.countNumberOfPolytomies( species_tree );
1533 if ( gsdir.getStrippedExternalGeneTreeNodes().size() > 0 ) {
1534 JOptionPane.showMessageDialog( this,
1535 "Minimal duplications: " + gsdir.getMinDuplicationsSum() + "\n"
1536 + "Speciations: " + gsdir.getSpeciationsSum() + "\n"
1537 + "Stripped gene tree nodes: "
1538 + gsdir.getStrippedExternalGeneTreeNodes().size() + "\n"
1539 + "Taxonomy linkage based on: " + gsdir.getTaxCompBase() + "\n"
1540 + "Number of polytomies in species tree used: " + poly + "\n",
1541 "GSDIR successfully completed",
1542 JOptionPane.WARNING_MESSAGE );
1545 JOptionPane.showMessageDialog( this,
1546 "Minimal duplications: " + gsdir.getMinDuplicationsSum() + "\n"
1547 + "Speciations: " + gsdir.getSpeciationsSum() + "\n"
1548 + "Stripped gene tree nodes: "
1549 + gsdir.getStrippedExternalGeneTreeNodes().size() + "\n"
1550 + "Taxonomy linkage based on: " + gsdir.getTaxCompBase() + "\n"
1551 + "Number of polytomies in species tree used: " + poly + "\n",
1552 "GSDIR successfully completed",
1553 JOptionPane.INFORMATION_MESSAGE );
1557 void executeLineageInference() {
1558 if ( ( _mainpanel.getCurrentPhylogeny() == null ) || ( _mainpanel.getCurrentPhylogeny().isEmpty() ) ) {
1561 if ( !_mainpanel.getCurrentPhylogeny().isRooted() ) {
1562 JOptionPane.showMessageDialog( this,
1563 "Phylogeny is not rooted.",
1564 "Cannot infer ancestral taxonomies",
1565 JOptionPane.ERROR_MESSAGE );
1568 final AncestralTaxonomyInferrer inferrer = new AncestralTaxonomyInferrer( this,
1569 _mainpanel.getCurrentTreePanel(),
1570 _mainpanel.getCurrentPhylogeny()
1572 new Thread( inferrer ).start();
1575 boolean GAndSDoHaveMoreThanOneSpeciesInComman( final Phylogeny gene_tree ) {
1576 if ( ( gene_tree == null ) || gene_tree.isEmpty() ) {
1577 JOptionPane.showMessageDialog( this,
1578 "Gene tree and species tree have no species in common.",
1580 JOptionPane.ERROR_MESSAGE );
1583 else if ( gene_tree.getNumberOfExternalNodes() < 2 ) {
1584 JOptionPane.showMessageDialog( this,
1585 "Gene tree and species tree have only one species in common.",
1587 JOptionPane.ERROR_MESSAGE );
1595 ControlPanel getControlPanel() {
1596 return getMainPanel().getControlPanel();
1599 File getCurrentDir() {
1600 if ( ( _current_dir == null ) || !_current_dir.canRead() ) {
1601 if ( ForesterUtil.isWindows() ) {
1603 _current_dir = new File( WindowsUtils.getCurrentUserDesktopPath() );
1605 catch ( final Exception e ) {
1606 _current_dir = null;
1610 if ( ( _current_dir == null ) || !_current_dir.canRead() ) {
1611 if ( System.getProperty( "user.home" ) != null ) {
1612 _current_dir = new File( System.getProperty( "user.home" ) );
1614 else if ( System.getProperty( "user.dir" ) != null ) {
1615 _current_dir = new File( System.getProperty( "user.dir" ) );
1618 return _current_dir;
1621 TreePanel getCurrentTreePanel() {
1622 return getMainPanel().getCurrentTreePanel();
1625 JMenu getHelpMenu() {
1629 JCheckBoxMenuItem getlabelDirectionCbmi() {
1630 return _label_direction_cbmi;
1633 JMenuBar getMenuBarOfMainFrame() {
1637 final Phylogeny getSpeciesTree() {
1638 return _species_tree;
1641 void initializeTypeMenu( final Options options ) {
1642 setTypeMenuToAllUnselected();
1643 switch ( options.getPhylogenyGraphicsType() ) {
1645 _convex_type_cbmi.setSelected( true );
1648 _curved_type_cbmi.setSelected( true );
1651 _euro_type_cbmi.setSelected( true );
1654 _rounded_type_cbmi.setSelected( true );
1657 _triangular_type_cbmi.setSelected( true );
1660 _unrooted_type_cbmi.setSelected( true );
1663 _circular_type_cbmi.setSelected( true );
1666 _rectangular_type_cbmi.setSelected( true );
1671 boolean isOKforSDI( final boolean species_tree_has_to_binary, final boolean gene_tree_has_to_binary ) {
1672 if ( ( _mainpanel.getCurrentPhylogeny() == null ) || _mainpanel.getCurrentPhylogeny().isEmpty() ) {
1675 else if ( ( getSpeciesTree() == null ) || getSpeciesTree().isEmpty() ) {
1676 JOptionPane.showMessageDialog( this,
1677 "No species tree loaded",
1678 "Cannot execute GSDI",
1679 JOptionPane.ERROR_MESSAGE );
1682 else if ( species_tree_has_to_binary && !getSpeciesTree().isCompletelyBinary() ) {
1683 JOptionPane.showMessageDialog( this,
1684 "Species tree is not completely binary",
1685 "Cannot execute GSDI",
1686 JOptionPane.ERROR_MESSAGE );
1689 else if ( gene_tree_has_to_binary && !_mainpanel.getCurrentPhylogeny().isCompletelyBinary() ) {
1690 JOptionPane.showMessageDialog( this,
1691 "Gene tree is not completely binary",
1692 "Cannot execute GSDI",
1693 JOptionPane.ERROR_MESSAGE );
1701 boolean isSubtreeDisplayed() {
1702 if ( getCurrentTreePanel() != null ) {
1703 if ( getCurrentTreePanel().isCurrentTreeIsSubtree() ) {
1705 .showMessageDialog( this,
1706 "This operation can only be performed on a complete tree, not on the currently displayed sub-tree only.",
1707 "Operation can not be exectuted on a sub-tree",
1708 JOptionPane.WARNING_MESSAGE );
1715 void midpointRoot() {
1716 if ( _mainpanel.getCurrentTreePanel() != null ) {
1717 _mainpanel.getCurrentTreePanel().midpointRoot();
1721 void readPhylogeniesFromWebservice( final int i ) {
1722 final UrlTreeReader reader = new UrlTreeReader( this, i );
1723 new Thread( reader ).start();
1726 void removeAllTextFrames() {
1727 for( final TextFrame tf : _textframes ) {
1732 _textframes.clear();
1735 void resetSearch() {
1736 getMainPanel().getCurrentTreePanel().setFoundNodes0( null );
1737 getMainPanel().getCurrentTreePanel().setFoundNodes1( null );
1738 getMainPanel().getControlPanel().setSearchFoundCountsOnLabel0( 0 );
1739 getMainPanel().getControlPanel().getSearchFoundCountsLabel0().setVisible( false );
1740 getMainPanel().getControlPanel().getSearchTextField0().setText( "" );
1741 getMainPanel().getControlPanel().getSearchResetButton0().setEnabled( false );
1742 getMainPanel().getControlPanel().getSearchResetButton0().setVisible( false );
1743 getMainPanel().getControlPanel().setSearchFoundCountsOnLabel1( 0 );
1744 getMainPanel().getControlPanel().getSearchFoundCountsLabel1().setVisible( false );
1745 getMainPanel().getControlPanel().getSearchTextField1().setText( "" );
1746 getMainPanel().getControlPanel().getSearchResetButton1().setEnabled( false );
1747 getMainPanel().getControlPanel().getSearchResetButton1().setVisible( false );
1750 void setConfiguration( final Configuration configuration ) {
1751 _configuration = configuration;
1754 void setCurrentDir( final File current_dir ) {
1755 _current_dir = current_dir;
1758 void setInferenceManager( final InferenceManager i ) {
1759 _inference_manager = i;
1762 void setOptions( final Options options ) {
1766 void setSelectedTypeInTypeMenu( final PHYLOGENY_GRAPHICS_TYPE type ) {
1767 setTypeMenuToAllUnselected();
1770 _circular_type_cbmi.setSelected( true );
1773 _convex_type_cbmi.setSelected( true );
1776 _curved_type_cbmi.setSelected( true );
1779 _euro_type_cbmi.setSelected( true );
1782 _rounded_type_cbmi.setSelected( true );
1785 _rectangular_type_cbmi.setSelected( true );
1788 _triangular_type_cbmi.setSelected( true );
1791 _unrooted_type_cbmi.setSelected( true );
1794 throw new IllegalArgumentException( "unknown type: " + type );
1798 final void setSpeciesTree( final Phylogeny species_tree ) {
1799 _species_tree = species_tree;
1802 void setTypeMenuToAllUnselected() {
1803 _convex_type_cbmi.setSelected( false );
1804 _curved_type_cbmi.setSelected( false );
1805 _euro_type_cbmi.setSelected( false );
1806 _rounded_type_cbmi.setSelected( false );
1807 _triangular_type_cbmi.setSelected( false );
1808 _rectangular_type_cbmi.setSelected( false );
1809 _unrooted_type_cbmi.setSelected( false );
1810 _circular_type_cbmi.setSelected( false );
1813 void switchColors() {
1814 final TreeColorSet colorset = _mainpanel.getTreeColorSet();
1815 final ColorSchemeChooser csc = new ColorSchemeChooser( getMainPanel(), colorset );
1816 csc.setVisible( true );
1820 if ( _mainpanel.getCurrentTreePanel() != null ) {
1821 _mainpanel.getCurrentTreePanel().taxColor();
1825 void typeChanged( final Object o ) {
1826 updateTypeCheckboxes( getOptions(), o );
1827 updateOptions( getOptions() );
1828 if ( getCurrentTreePanel() != null ) {
1829 final PHYLOGENY_GRAPHICS_TYPE previous_type = getCurrentTreePanel().getPhylogenyGraphicsType();
1830 final PHYLOGENY_GRAPHICS_TYPE new_type = getOptions().getPhylogenyGraphicsType();
1831 if ( ( ( previous_type == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) && ( new_type != PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) )
1832 || ( ( previous_type == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) && ( new_type != PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) )
1833 || ( ( previous_type != PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) && ( new_type == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) )
1834 || ( ( previous_type != PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) && ( new_type == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) ) ) {
1835 getCurrentTreePanel().getControlPanel().showWhole();
1837 if ( getCurrentTreePanel().isPhyHasBranchLengths() && ( new_type != PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) ) {
1838 getCurrentTreePanel().getControlPanel().setDrawPhylogramEnabled( true );
1841 getCurrentTreePanel().getControlPanel().setDrawPhylogramEnabled( false );
1843 getCurrentTreePanel().setPhylogenyGraphicsType( getOptions().getPhylogenyGraphicsType() );
1844 updateScreenTextAntialias( getMainPanel().getTreePanels() );
1845 if ( getCurrentTreePanel().getControlPanel().getDynamicallyHideData() != null ) {
1846 if ( new_type == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) {
1847 getCurrentTreePanel().getControlPanel().getDynamicallyHideData().setEnabled( false );
1850 getCurrentTreePanel().getControlPanel().getDynamicallyHideData().setEnabled( true );
1856 void updateOptions( final Options options ) {
1857 options.setAntialiasScreen( ( _screen_antialias_cbmi != null ) && _screen_antialias_cbmi.isSelected() );
1858 options.setBackgroundColorGradient( ( _background_gradient_cbmi != null )
1859 && _background_gradient_cbmi.isSelected() );
1860 options.setShowDomainLabels( ( _show_domain_labels != null ) && _show_domain_labels.isSelected() );
1861 options.setShowAnnotationRefSource( ( _show_annotation_ref_source != null )
1862 && _show_annotation_ref_source.isSelected() );
1863 options.setAbbreviateScientificTaxonNames( ( _abbreviate_scientific_names != null )
1864 && _abbreviate_scientific_names.isSelected() );
1865 options.setColorLabelsSameAsParentBranch( ( _color_labels_same_as_parent_branch != null )
1866 && _color_labels_same_as_parent_branch.isSelected() );
1867 options.setShowDefaultNodeShapesInternal( ( _show_default_node_shapes_internal_cbmi != null )
1868 && _show_default_node_shapes_internal_cbmi.isSelected() );
1869 options.setShowDefaultNodeShapesExternal( ( _show_default_node_shapes_external_cbmi != null )
1870 && _show_default_node_shapes_external_cbmi.isSelected() );
1871 options.setShowDefaultNodeShapesForMarkedNodes( ( _show_default_node_shapes_for_marked_cbmi != null )
1872 && _show_default_node_shapes_for_marked_cbmi.isSelected() );
1873 if ( ( _non_lined_up_cladograms_rbmi != null ) && ( _non_lined_up_cladograms_rbmi.isSelected() ) ) {
1874 options.setCladogramType( CLADOGRAM_TYPE.NON_LINED_UP );
1876 else if ( ( _ext_node_dependent_cladogram_rbmi != null ) && ( _ext_node_dependent_cladogram_rbmi.isSelected() ) ) {
1877 options.setCladogramType( CLADOGRAM_TYPE.LINED_UP );
1879 options.setSearchCaseSensitive( ( _search_case_senstive_cbmi != null )
1880 && _search_case_senstive_cbmi.isSelected() );
1881 if ( ( _show_scale_cbmi != null ) && _show_scale_cbmi.isEnabled() ) {
1882 options.setShowScale( _show_scale_cbmi.isSelected() );
1884 if ( _label_direction_cbmi != null ) {
1885 if ( _label_direction_cbmi.isSelected() ) {
1886 options.setNodeLabelDirection( NODE_LABEL_DIRECTION.RADIAL );
1889 options.setNodeLabelDirection( NODE_LABEL_DIRECTION.HORIZONTAL );
1892 options.setShowOverview( ( _show_overview_cbmi != null ) && _show_overview_cbmi.isSelected() );
1893 options.setShowConfidenceStddev( ( _show_confidence_stddev_cbmi != null )
1894 && _show_confidence_stddev_cbmi.isSelected() );
1895 if ( ( _color_by_taxonomic_group_cbmi != null ) && _color_by_taxonomic_group_cbmi.isEnabled() ) {
1896 options.setColorByTaxonomicGroup( _color_by_taxonomic_group_cbmi.isSelected() );
1898 options.setAntialiasPrint( ( _antialias_print_cbmi != null ) && _antialias_print_cbmi.isSelected() );
1899 if ( ( _use_brackets_for_conf_in_nh_export_cbmi != null )
1900 && _use_brackets_for_conf_in_nh_export_cbmi.isSelected() ) {
1901 options.setNhConversionSupportValueStyle( NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS );
1903 else if ( ( _use_internal_names_for_conf_in_nh_export_cbmi != null )
1904 && _use_internal_names_for_conf_in_nh_export_cbmi.isSelected() ) {
1905 options.setNhConversionSupportValueStyle( NH_CONVERSION_SUPPORT_VALUE_STYLE.AS_INTERNAL_NODE_NAMES );
1908 options.setNhConversionSupportValueStyle( NH_CONVERSION_SUPPORT_VALUE_STYLE.NONE );
1910 options.setPrintBlackAndWhite( ( _print_black_and_white_cbmi != null )
1911 && _print_black_and_white_cbmi.isSelected() );
1912 options.setInternalNumberAreConfidenceForNhParsing( ( _internal_number_are_confidence_for_nh_parsing_cbmi != null )
1913 && _internal_number_are_confidence_for_nh_parsing_cbmi.isSelected() );
1914 if ( ( _extract_taxonomy_pfam_strict_rbmi != null ) && _extract_taxonomy_pfam_strict_rbmi.isSelected() ) {
1915 options.setTaxonomyExtraction( TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1917 else if ( ( _extract_taxonomy_pfam_relaxed_rbmi != null ) && _extract_taxonomy_pfam_relaxed_rbmi.isSelected() ) {
1918 options.setTaxonomyExtraction( TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
1920 else if ( ( _extract_taxonomy_agressive_rbmi != null ) && _extract_taxonomy_agressive_rbmi.isSelected() ) {
1921 options.setTaxonomyExtraction( TAXONOMY_EXTRACTION.AGGRESSIVE );
1923 else if ( ( _extract_taxonomy_no_rbmi != null ) && _extract_taxonomy_no_rbmi.isSelected() ) {
1924 options.setTaxonomyExtraction( TAXONOMY_EXTRACTION.NO );
1926 options.setReplaceUnderscoresInNhParsing( ( _replace_underscores_cbmi != null )
1927 && _replace_underscores_cbmi.isSelected() );
1928 options.setAllowErrorsInDistanceToParent( ( _allow_errors_in_distance_to_parent_cbmi != null )
1929 && _allow_errors_in_distance_to_parent_cbmi.isSelected() );
1930 options.setMatchWholeTermsOnly( ( _search_whole_words_only_cbmi != null )
1931 && _search_whole_words_only_cbmi.isSelected() );
1932 options.setSearchWithRegex( ( _search_with_regex_cbmi != null ) && _search_with_regex_cbmi.isSelected() );
1933 options.setInverseSearchResult( ( _inverse_search_result_cbmi != null )
1934 && _inverse_search_result_cbmi.isSelected() );
1935 if ( _graphics_export_visible_only_cbmi != null ) {
1936 options.setGraphicsExportVisibleOnly( _graphics_export_visible_only_cbmi.isSelected() );
1938 if ( ( _rectangular_type_cbmi != null ) && _rectangular_type_cbmi.isSelected() ) {
1939 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR );
1941 else if ( ( _triangular_type_cbmi != null ) && _triangular_type_cbmi.isSelected() ) {
1942 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.TRIANGULAR );
1944 else if ( ( _curved_type_cbmi != null ) && _curved_type_cbmi.isSelected() ) {
1945 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CURVED );
1947 else if ( ( _convex_type_cbmi != null ) && _convex_type_cbmi.isSelected() ) {
1948 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CONVEX );
1950 else if ( ( _euro_type_cbmi != null ) && _euro_type_cbmi.isSelected() ) {
1951 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE );
1953 else if ( ( _rounded_type_cbmi != null ) && _rounded_type_cbmi.isSelected() ) {
1954 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.ROUNDED );
1956 else if ( ( _unrooted_type_cbmi != null ) && _unrooted_type_cbmi.isSelected() ) {
1957 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.UNROOTED );
1959 else if ( ( _circular_type_cbmi != null ) && _circular_type_cbmi.isSelected() ) {
1960 options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CIRCULAR );
1962 if ( ( _right_line_up_domains_cbmi != null ) && _right_line_up_domains_cbmi.isEnabled() ) {
1963 options.setRightLineUpDomains( _right_line_up_domains_cbmi.isSelected() );
1965 if ( ( _line_up_renderable_data_cbmi != null ) && _line_up_renderable_data_cbmi.isEnabled() ) {
1966 options.setLineUpRendarableNodeData( _line_up_renderable_data_cbmi.isSelected() );
1968 if ( ( _color_all_found_nodes_when_coloring_subtree_cbmi != null ) && _color_all_found_nodes_when_coloring_subtree_cbmi.isEnabled() ) {
1969 options.setColorAllFoundNodesWhenColoringSubtree( _color_all_found_nodes_when_coloring_subtree_cbmi.isSelected() );
1971 if ( ( _parse_beast_style_extended_nexus_tags_cbmi != null ) && _parse_beast_style_extended_nexus_tags_cbmi.isEnabled() ) {
1972 options.setParseBeastStyleExtendedNexusTags(_parse_beast_style_extended_nexus_tags_cbmi.isSelected() );
1974 if ( ( _collapsed_with_average_height_cbmi != null ) && _collapsed_with_average_height_cbmi.isEnabled() ) {
1975 options.setCollapsedWithAverageHeigh(_collapsed_with_average_height_cbmi.isSelected() );
1977 if ( ( _show_abbreviated_labels_for_collapsed_nodes_cbmi != null ) && _show_abbreviated_labels_for_collapsed_nodes_cbmi.isEnabled() ) {
1978 options.setShowAbbreviatedLabelsForCollapsedNodes(_show_abbreviated_labels_for_collapsed_nodes_cbmi.isSelected() );
1983 void updateTypeCheckboxes( final Options options, final Object o ) {
1984 setTypeMenuToAllUnselected();
1985 ( ( JCheckBoxMenuItem ) o ).setSelected( true );
1988 void viewAsNexus() {
1989 if ( ( _mainpanel.getCurrentPhylogeny() != null ) && !_mainpanel.getCurrentPhylogeny().isEmpty() ) {
1990 String title = "Nexus";
1991 if ( !ForesterUtil.isEmpty( _mainpanel.getCurrentPhylogeny().getName() ) ) {
1992 title = "\"" + getMainPanel().getCurrentPhylogeny().getName() + "\" in " + title;
1994 showTextFrame( _mainpanel.getCurrentPhylogeny().toNexus( getOptions().getNhConversionSupportValueStyle() ),
2000 if ( ( _mainpanel.getCurrentPhylogeny() != null ) && !_mainpanel.getCurrentPhylogeny().isEmpty() ) {
2001 String title = "New Hampshire";
2002 if ( !ForesterUtil.isEmpty( _mainpanel.getCurrentPhylogeny().getName() ) ) {
2003 title = "\"" + getMainPanel().getCurrentPhylogeny().getName() + "\" in " + title;
2005 showTextFrame( _mainpanel.getCurrentPhylogeny().toNewHampshire( getOptions()
2006 .getNhConversionSupportValueStyle() ),
2012 if ( ( _mainpanel.getCurrentPhylogeny() != null ) && !_mainpanel.getCurrentPhylogeny().isEmpty() ) {
2013 String title = "phyloXML";
2014 if ( !ForesterUtil.isEmpty( _mainpanel.getCurrentPhylogeny().getName() ) ) {
2015 title = "\"" + getMainPanel().getCurrentPhylogeny().getName() + "\" in " + title;
2017 showTextFrame( _mainpanel.getCurrentPhylogeny().toPhyloXML( 0 ), title );
2021 private static void cycleNodeDataReturn( final Options op, final Configuration conf ) {
2022 switch ( op.getExtDescNodeDataToReturn() ) {
2024 op.setExtDescNodeDataToReturn( NodeDataField.DOMAINS_ALL );
2027 op.setExtDescNodeDataToReturn( NodeDataField.DOMAINS_COLLAPSED_PER_PROTEIN );
2029 case DOMAINS_COLLAPSED_PER_PROTEIN:
2030 op.setExtDescNodeDataToReturn( NodeDataField.SEQ_ANNOTATIONS );
2032 case SEQ_ANNOTATIONS:
2033 op.setExtDescNodeDataToReturn( NodeDataField.GO_TERM_IDS );
2036 op.setExtDescNodeDataToReturn( NodeDataField.SEQUENCE_MOL_SEQ_FASTA );
2038 case SEQUENCE_MOL_SEQ_FASTA:
2039 if ( ( conf != null ) && ( conf.getExtDescNodeDataToReturn() != null )
2040 && ( conf.getExtDescNodeDataToReturn() != NodeDataField.DOMAINS_ALL )
2041 && ( conf.getExtDescNodeDataToReturn() != NodeDataField.DOMAINS_COLLAPSED_PER_PROTEIN )
2042 && ( conf.getExtDescNodeDataToReturn() != NodeDataField.SEQ_ANNOTATIONS )
2043 && ( conf.getExtDescNodeDataToReturn() != NodeDataField.GO_TERM_IDS )
2044 && ( conf.getExtDescNodeDataToReturn() != NodeDataField.SEQUENCE_MOL_SEQ_FASTA ) ) {
2045 op.setExtDescNodeDataToReturn( conf.getExtDescNodeDataToReturn() );
2048 op.setExtDescNodeDataToReturn( NodeDataField.UNKNOWN );
2052 op.setExtDescNodeDataToReturn( NodeDataField.UNKNOWN );
2057 * Display the about box.
2060 final StringBuffer about = new StringBuffer( "Archaeopteryx\nVersion " + AptxConstants.VERSION + "\n" );
2061 about.append( "Copyright (C) 2016 Christian M Zmasek\n" );
2062 about.append( "All Rights Reserved\n" );
2063 about.append( "License: GNU Lesser General Public License (LGPL)\n" );
2064 about.append( "Last modified: " + AptxConstants.PRG_DATE + "\n" );
2065 about.append( "Based on: " + ForesterUtil.getForesterLibraryInformation() + "\n" );
2067 if ( _configuration.isCouldReadConfigFile() ) {
2068 about.append( "Using configuration file: " + _configuration.config_filename + "\n" );
2071 about.append( "Not using a configuration file\n" );
2074 about.append( "phyloXML version : " + ForesterConstants.PHYLO_XML_VERSION + "\n" );
2075 about.append( "phyloXML location: " + ForesterConstants.PHYLO_XML_LOCATION + "\n" );
2076 if ( !ForesterUtil.isEmpty( ForesterUtil.JAVA_VERSION ) && !ForesterUtil.isEmpty( ForesterUtil.JAVA_VENDOR ) ) {
2077 about.append( "[your Java version: " + ForesterUtil.JAVA_VERSION + " " + ForesterUtil.JAVA_VENDOR + "]\n" );
2079 if ( !ForesterUtil.isEmpty( ForesterUtil.OS_NAME ) && !ForesterUtil.isEmpty( ForesterUtil.OS_ARCH )
2080 && !ForesterUtil.isEmpty( ForesterUtil.OS_VERSION ) ) {
2081 about.append( "[your OS: " + ForesterUtil.OS_NAME + " " + ForesterUtil.OS_ARCH + " "
2082 + ForesterUtil.OS_VERSION + "]\n" );
2084 final Runtime rt = java.lang.Runtime.getRuntime();
2085 final long free_memory = rt.freeMemory() / 1000000;
2086 final long total_memory = rt.totalMemory() / 1000000;
2087 about.append( "[free memory: " + free_memory + "MB, total memory: " + total_memory + "MB]\n" );
2088 about.append( "[locale: " + Locale.getDefault() + "]\n" );
2089 about.append( "References:\n" );
2090 about.append( AptxConstants.PHYLOXML_REFERENCE_SHORT + "\n" );
2091 about.append( "For more information & download:\n" );
2092 about.append( AptxConstants.APTX_WEB_SITE + "\n" );
2093 about.append( "Documentation:\n" );
2094 about.append( AptxConstants.APTX_DOC_SITE + "\n" );
2095 about.append( "Comments: " + AptxConstants.AUTHOR_EMAIL );
2096 JOptionPane.showMessageDialog( null, about, AptxConstants.PRG_NAME, JOptionPane.PLAIN_MESSAGE );
2099 static void chooseNodeSize( final Options options, final Component parent ) {
2100 final String s = ( String ) JOptionPane.showInputDialog( parent,
2101 "Please enter the default size for node shapes.\n"
2102 + "[current value: "
2103 + options.getDefaultNodeShapeSize() + "]\n",
2105 JOptionPane.QUESTION_MESSAGE,
2108 options.getDefaultNodeShapeSize() );
2109 if ( !ForesterUtil.isEmpty( s ) ) {
2110 boolean success = true;
2112 final String m_str = s.trim();
2113 if ( !ForesterUtil.isEmpty( m_str ) ) {
2115 m = Double.parseDouble( m_str );
2117 catch ( final Exception ex ) {
2124 if ( success && ( m >= 0.0 ) ) {
2125 final short size = ForesterUtil.roundToShort( m );
2126 if ( size >= 0.0 ) {
2127 options.setDefaultNodeShapeSize( size );
2133 static String createCurrentFontDesc( final TreeFontSet tree_font_set ) {
2134 return tree_font_set.getLargeFont().getFamily() + " " + tree_font_set.getLargeFont().getSize();
2137 static JMenu createMenu( final String title, final Configuration conf ) {
2138 final JMenu jmenu = new JMenu( title );
2139 if ( !conf.isUseNativeUI() ) {
2140 jmenu.setFont( MainFrame.menu_font );
2141 jmenu.setBackground( conf.getGuiMenuBackgroundColor() );
2142 jmenu.setForeground( conf.getGuiMenuTextColor() );
2147 static JMenuItem customizeMenuItemAsLabel( final JMenuItem label, final Configuration configuration ) {
2148 label.setFont( MainFrame.menu_font.deriveFont( Font.BOLD ) );
2149 if ( !configuration.isUseNativeUI() ) {
2150 label.setBackground( configuration.getGuiMenuBackgroundColor() );
2151 label.setForeground( configuration.getGuiMenuTextColor() );
2152 label.setOpaque( true );
2154 label.setSelected( false );
2155 label.setEnabled( false );
2159 static void cycleNodeFill( final Options op ) {
2160 switch ( op.getDefaultNodeFill() ) {
2162 op.setDefaultNodeFill( NodeFill.SOLID );
2165 op.setDefaultNodeFill( NodeFill.GRADIENT );
2168 op.setDefaultNodeFill( NodeFill.NONE );
2171 throw new RuntimeException( "unknown fill: " + op.getDefaultNodeFill() );
2175 static void cycleNodeShape( final Options op ) {
2176 switch ( op.getDefaultNodeShape() ) {
2178 op.setDefaultNodeShape( NodeShape.RECTANGLE );
2181 op.setDefaultNodeShape( NodeShape.CIRCLE );
2184 throw new RuntimeException( "unknown shape: " + op.getDefaultNodeShape() );
2188 static void cycleOverview( final Options op, final TreePanel tree_panel ) {
2189 switch ( op.getOvPlacement() ) {
2191 op.setOvPlacement( Options.OVERVIEW_PLACEMENT_TYPE.UPPER_LEFT );
2194 op.setOvPlacement( Options.OVERVIEW_PLACEMENT_TYPE.LOWER_LEFT );
2197 op.setOvPlacement( Options.OVERVIEW_PLACEMENT_TYPE.UPPER_RIGHT );
2200 op.setOvPlacement( Options.OVERVIEW_PLACEMENT_TYPE.LOWER_RIGHT );
2203 throw new RuntimeException( "unknown placement: " + op.getOvPlacement() );
2205 if ( tree_panel != null ) {
2206 tree_panel.updateOvSettings();
2210 static void exceptionOccuredDuringSaveAs( final Exception e, final TreePanel tp, final Component comp ) {
2212 tp.setArrowCursor();
2214 catch ( final Exception ex ) {
2217 JOptionPane.showMessageDialog( comp, "Exception" + e, "Error during File|SaveAs", JOptionPane.ERROR_MESSAGE );
2220 static void print( final TreePanel tp, final Options op, final Component c ) {
2221 if ( ( tp == null ) || ( tp.getPhylogeny() == null ) || tp.getPhylogeny().isEmpty() ) {
2224 final String job_name = AptxConstants.PRG_NAME;
2225 boolean error = false;
2226 String printer_name = null;
2228 printer_name = Printer.print( tp, job_name );
2230 catch ( final Exception e ) {
2232 JOptionPane.showMessageDialog( c, e.getMessage(), "Printing Error", JOptionPane.ERROR_MESSAGE );
2234 if ( !error && ( printer_name != null ) ) {
2235 String msg = "Printing data sent to printer";
2236 if ( printer_name.length() > 1 ) {
2237 msg += " [" + printer_name + "]";
2239 JOptionPane.showMessageDialog( c, msg, "Printing...", JOptionPane.INFORMATION_MESSAGE );
2241 if ( !op.isPrintUsingActualSize() ) {
2242 tp.getControlPanel().showWhole();
2246 static void printPhylogenyToPdf( final String file_name,
2249 final Component comp ) {
2251 String pdf_written_to = "";
2252 boolean error = false;
2254 if ( opts.isPrintUsingActualSize() ) {
2255 pdf_written_to = PdfExporter.writePhylogenyToPdf( file_name, tp, tp.getWidth() , tp.getHeight() );
2261 catch ( final IOException e ) {
2263 JOptionPane.showMessageDialog( comp, e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE );
2266 if ( !ForesterUtil.isEmpty( pdf_written_to ) ) {
2267 JOptionPane.showMessageDialog( comp,
2268 "Wrote PDF to: " + pdf_written_to,
2270 JOptionPane.INFORMATION_MESSAGE );
2273 JOptionPane.showMessageDialog( comp,
2274 "There was an unknown problem when attempting to write to PDF file: \""
2277 JOptionPane.ERROR_MESSAGE );
2280 if ( !opts.isPrintUsingActualSize() ) {
2281 tp.getControlPanel().showWhole();
2285 static void setCycleDataReturnMenuItem( final JMenuItem mi, final Options options ) {
2286 if ( ( options != null ) && ( options.getExtDescNodeDataToReturn() != null ) ) {
2287 mi.setText( "Cycle Node Return Data... (current: " + options.getExtDescNodeDataToReturn().toString() + ")" );
2290 mi.setText( "Cycle Node Return Data..." );
2294 static void setCycleNodeFillMenuItem( final JMenuItem mi, final Options options ) {
2295 if ( ( options != null ) && ( options.getDefaultNodeFill() != null ) ) {
2296 mi.setText( "Cycle Node Shape Fill Type... (current: "
2297 + options.getDefaultNodeFill().toString().toLowerCase() + ")" );
2300 mi.setText( "Cycle Node Shape Fill Type..." );
2304 static void setCycleNodeShapeMenuItem( final JMenuItem mi, final Options options ) {
2305 if ( ( options != null ) && ( options.getDefaultNodeShape() != null ) ) {
2306 mi.setText( "Cycle Node Shape Fill Type... (current: "
2307 + options.getDefaultNodeShape().toString().toLowerCase() + ")" );
2310 mi.setText( "Cycle Node Shape Fill Type..." );
2314 static void setOvPlacementColorChooseMenuItem( final JMenuItem mi, final Options options ) {
2315 if ( ( options != null ) && ( options.getOvPlacement() != null ) ) {
2316 mi.setText( "Cycle Overview Placement... (current: " + options.getOvPlacement() + ")" );
2319 mi.setText( "Cycle Overview Placement..." );
2323 static void setTextColorChooseMenuItem( final JMenuItem mi, final TreePanel tree_panel ) {
2324 if ( ( tree_panel != null ) && ( tree_panel.getTreeColorSet() != null ) ) {
2325 mi.setText( "Select Color Scheme... (current: " + tree_panel.getTreeColorSet().getCurrentColorSchemeName()
2329 mi.setText( "Select Color Scheme..." );
2333 static void setTextForFontChooserMenuItem( final JMenuItem mi, final String font_desc ) {
2334 mi.setText( "Select Default Font... (current: " + font_desc + ")" );
2337 static void setTextForPdfLineWidthChooserMenuItem( final JMenuItem mi, final Options o ) {
2338 mi.setText( "Enter Default Line Width for PDF Export... (current: " + o.getPrintLineWidth() + ")" );
2341 static void setTextMinSupportMenuItem( final JMenuItem mi, final Options options, final TreePanel current_tree_panel ) {
2342 if ( ( current_tree_panel == null ) || ( current_tree_panel.getPhylogeny() == null ) ) {
2343 mi.setEnabled( true );
2345 else if ( AptxUtil.isHasAtLeastOneBranchWithSupportValues( current_tree_panel.getPhylogeny() ) ) {
2346 mi.setEnabled( true );
2349 mi.setEnabled( false );
2351 mi.setText( "Enter Min Confidence Value... (current: " + options.getMinConfidenceValue() + ")" );
2354 static void setTextNodeSizeMenuItem( final JMenuItem mi, final Options options ) {
2355 mi.setText( "Enter Default Node Shape Size... (current: " + options.getDefaultNodeShapeSize() + ")" );
2358 static void updateScreenTextAntialias( final List<TreePanel> treepanels ) {
2359 for( final TreePanel tree_panel : treepanels ) {
2360 tree_panel.setTextAntialias();
2364 static boolean writeAsNewHampshire( final TreePanel tp, final Options op, boolean exception, final File file ) {
2366 final PhylogenyWriter writer = new PhylogenyWriter();
2367 writer.toNewHampshire( tp.getPhylogeny(), true, op.getNhConversionSupportValueStyle(), file );
2369 catch ( final Exception e ) {
2371 exceptionOccuredDuringSaveAs( e, tp, tp );
2376 static boolean writeAsNexus( final TreePanel tp, final Options op, boolean exception, final File file ) {
2378 final PhylogenyWriter writer = new PhylogenyWriter();
2379 writer.toNexus( file, tp.getPhylogeny(), op.getNhConversionSupportValueStyle() );
2381 catch ( final Exception e ) {
2383 exceptionOccuredDuringSaveAs( e, tp, tp );
2388 static boolean writeAsPhyloXml( final TreePanel tp, final Options op, boolean exception, final File file ) {
2390 final PhylogenyWriter writer = new PhylogenyWriter();
2391 writer.toPhyloXML( file, tp.getPhylogeny(), 0 );
2393 catch ( final Exception e ) {
2395 exceptionOccuredDuringSaveAs( e, tp, tp );
2400 static void writePhylogenyToGraphicsFile( final String file_name,
2401 final GraphicsExportType type,
2403 final Component comp,
2404 final Container contentpane ) {
2405 mp.getCurrentTreePanel().calcParametersForPainting( mp.getCurrentTreePanel().getWidth(),
2406 mp.getCurrentTreePanel().getHeight() );
2407 String file_written_to = "";
2408 boolean error = false;
2410 file_written_to = AptxUtil.writePhylogenyToGraphicsFile( file_name,
2411 mp.getCurrentTreePanel().getWidth(),
2412 mp.getCurrentTreePanel().getHeight(),
2413 mp.getCurrentTreePanel(),
2414 mp.getControlPanel(),
2418 catch ( final IOException e ) {
2420 JOptionPane.showMessageDialog( comp, e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE );
2423 if ( ( file_written_to != null ) && ( file_written_to.length() > 0 ) ) {
2424 JOptionPane.showMessageDialog( comp,
2425 "Wrote image to: " + file_written_to,
2427 JOptionPane.INFORMATION_MESSAGE );
2430 JOptionPane.showMessageDialog( comp,
2431 "There was an unknown problem when attempting to write to an image file: \""
2434 JOptionPane.ERROR_MESSAGE );
2437 contentpane.repaint();
2440 static File writeToFile( final Phylogeny t,
2442 final JFileChooser save_filechooser,
2443 final File current_dir,
2444 final Container contentpane,
2445 final Component comp ) {
2446 File new_file = null;
2450 String initial_filename = null;
2451 if ( mp.getCurrentTreePanel().getTreeFile() != null ) {
2453 initial_filename = mp.getCurrentTreePanel().getTreeFile().getCanonicalPath();
2455 catch ( final IOException e ) {
2456 initial_filename = null;
2459 if ( !ForesterUtil.isEmpty( initial_filename ) ) {
2460 save_filechooser.setSelectedFile( new File( initial_filename ) );
2463 save_filechooser.setSelectedFile( new File( "" ) );
2465 final File my_dir = current_dir;
2466 if ( my_dir != null ) {
2467 save_filechooser.setCurrentDirectory( my_dir );
2469 final int result = save_filechooser.showSaveDialog( contentpane );
2470 final File file = save_filechooser.getSelectedFile();
2471 new_file = save_filechooser.getCurrentDirectory();
2472 boolean exception = false;
2473 if ( ( file != null ) && ( result == JFileChooser.APPROVE_OPTION ) ) {
2474 if ( file.exists() ) {
2475 final int i = JOptionPane.showConfirmDialog( comp,
2476 file + " already exists.\nOverwrite?",
2478 JOptionPane.OK_CANCEL_OPTION,
2479 JOptionPane.QUESTION_MESSAGE );
2480 if ( i != JOptionPane.OK_OPTION ) {
2484 final File to = new File( file.getAbsoluteFile().toString() + AptxConstants.BACKUP_FILE_SUFFIX );
2486 ForesterUtil.copyFile( file, to );
2488 catch ( final Exception e ) {
2489 JOptionPane.showMessageDialog( comp,
2490 "Failed to create backup copy " + to,
2491 "Failed to Create Backup Copy",
2492 JOptionPane.WARNING_MESSAGE );
2497 catch ( final Exception e ) {
2498 JOptionPane.showMessageDialog( comp,
2499 "Failed to delete: " + file,
2501 JOptionPane.WARNING_MESSAGE );
2505 if ( save_filechooser.getFileFilter() == MainFrame.nhfilter ) {
2506 exception = writeAsNewHampshire( mp.getCurrentTreePanel(), mp.getOptions(), exception, file );
2508 else if ( save_filechooser.getFileFilter() == MainFrame.xmlfilter ) {
2509 exception = writeAsPhyloXml( mp.getCurrentTreePanel(), mp.getOptions(), exception, file );
2511 else if ( save_filechooser.getFileFilter() == MainFrame.nexusfilter ) {
2512 exception = writeAsNexus( mp.getCurrentTreePanel(), mp.getOptions(), exception, file );
2516 final String file_name = file.getName().trim().toLowerCase();
2517 if ( file_name.endsWith( ".nh" ) || file_name.endsWith( ".newick" ) || file_name.endsWith( ".phy" )
2518 || file_name.endsWith( ".tree" ) ) {
2519 exception = writeAsNewHampshire( mp.getCurrentTreePanel(), mp.getOptions(), exception, file );
2521 else if ( file_name.endsWith( ".nex" ) || file_name.endsWith( ".nexus" ) ) {
2522 exception = writeAsNexus( mp.getCurrentTreePanel(), mp.getOptions(), exception, file );
2526 exception = writeAsPhyloXml( mp.getCurrentTreePanel(), mp.getOptions(), exception, file );
2530 mp.setTitleOfSelectedTab( file.getName() );
2531 mp.getCurrentTreePanel().setTreeFile( file );
2532 mp.getCurrentTreePanel().setEdited( false );
2538 static File writeToGraphicsFile( final Phylogeny t,
2539 final GraphicsExportType type,
2541 final JFileChooser writetographics_filechooser,
2542 final Component component,
2543 final Container contentpane,
2544 final File current_dir ) {
2545 File new_dir = null;
2546 if ( ( t == null ) || t.isEmpty() ) {
2549 String initial_filename = "";
2550 if ( mp.getCurrentTreePanel().getTreeFile() != null ) {
2551 initial_filename = mp.getCurrentTreePanel().getTreeFile().toString();
2553 if ( initial_filename.indexOf( '.' ) > 0 ) {
2554 initial_filename = initial_filename.substring( 0, initial_filename.lastIndexOf( '.' ) );
2556 initial_filename = initial_filename + "." + type;
2557 writetographics_filechooser.setSelectedFile( new File( initial_filename ) );
2558 final File my_dir = current_dir;
2559 if ( my_dir != null ) {
2560 writetographics_filechooser.setCurrentDirectory( my_dir );
2562 final int result = writetographics_filechooser.showSaveDialog( contentpane );
2563 File file = writetographics_filechooser.getSelectedFile();
2564 //setCurrentDir( writetographics_filechooser.getCurrentDirectory() );
2565 new_dir = writetographics_filechooser.getCurrentDirectory();
2566 if ( ( file != null ) && ( result == JFileChooser.APPROVE_OPTION ) ) {
2567 if ( !file.toString().toLowerCase().endsWith( type.toString() ) ) {
2568 file = new File( file.toString() + "." + type );
2570 if ( file.exists() ) {
2571 final int i = JOptionPane.showConfirmDialog( component,
2572 file + " already exists. Overwrite?",
2574 JOptionPane.OK_CANCEL_OPTION,
2575 JOptionPane.WARNING_MESSAGE );
2576 if ( i != JOptionPane.OK_OPTION ) {
2583 catch ( final Exception e ) {
2584 JOptionPane.showMessageDialog( component,
2585 "Failed to delete: " + file,
2587 JOptionPane.WARNING_MESSAGE );
2591 writePhylogenyToGraphicsFile( file.toString(), type, mp, component, contentpane );
2596 static File writeToPdf( final Phylogeny t,
2598 final JFileChooser writetopdf_filechooser,
2599 final File curr_dir,
2600 final Container contentpane,
2601 final Component component ) {
2602 if ( ( t == null ) || t.isEmpty() ) {
2605 String initial_filename = "";
2606 if ( mp.getCurrentTreePanel().getTreeFile() != null ) {
2607 initial_filename = mp.getCurrentTreePanel().getTreeFile().toString();
2609 if ( initial_filename.indexOf( '.' ) > 0 ) {
2610 initial_filename = initial_filename.substring( 0, initial_filename.lastIndexOf( '.' ) );
2612 initial_filename = initial_filename + ".pdf";
2613 writetopdf_filechooser.setSelectedFile( new File( initial_filename ) );
2614 final File my_dir = curr_dir;
2615 if ( my_dir != null ) {
2616 writetopdf_filechooser.setCurrentDirectory( my_dir );
2618 final int result = writetopdf_filechooser.showSaveDialog( contentpane );
2619 File file = writetopdf_filechooser.getSelectedFile();
2620 // setCurrentDir( writetopdf_filechooser.getCurrentDirectory() );
2621 final File new_current_dir = writetopdf_filechooser.getCurrentDirectory();
2622 if ( ( file != null ) && ( result == JFileChooser.APPROVE_OPTION ) ) {
2623 if ( !file.toString().toLowerCase().endsWith( ".pdf" ) ) {
2624 file = new File( file.toString() + ".pdf" );
2626 if ( file.exists() ) {
2627 final int i = JOptionPane.showConfirmDialog( component,
2628 file + " already exists. Overwrite?",
2630 JOptionPane.OK_CANCEL_OPTION,
2631 JOptionPane.WARNING_MESSAGE );
2632 if ( i != JOptionPane.OK_OPTION ) {
2636 printPhylogenyToPdf( file.toString(), mp.getOptions(), mp.getCurrentTreePanel(), component );
2638 return new_current_dir;
2642 class DefaultFilter 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( ".nwk" ) || file_name.endsWith( ".phb" ) || file_name.endsWith( ".ph" )
2649 || file_name.endsWith( ".tr" ) || file_name.endsWith( ".dnd" ) || file_name.endsWith( ".tree" )
2650 || file_name.endsWith( ".nhx" ) || file_name.endsWith( ".xml" ) || file_name.endsWith( ".phyloxml" )
2651 || file_name.endsWith( "phylo.xml" ) || file_name.endsWith( ".pxml" ) || file_name.endsWith( ".nexus" )
2652 || file_name.endsWith( ".nx" ) || file_name.endsWith( ".nex" ) || file_name.endsWith( ".tre" )
2653 || file_name.endsWith( ".zip" ) || file_name.endsWith( ".tol" ) || file_name.endsWith( ".tolxml" )
2654 || file_name.endsWith( ".con" ) || f.isDirectory();
2658 public String getDescription() {
2659 return "All supported files (*.xml, *.phyloxml, *phylo.xml, *.nhx, *.nh, *.newick, *.nex, *.nexus, *.phy, *.tre, *.tree, *.tol, ...)";
2663 class GraphicsFileFilter extends FileFilter {
2666 public boolean accept( final File f ) {
2667 final String file_name = f.getName().trim().toLowerCase();
2668 return file_name.endsWith( ".jpg" ) || file_name.endsWith( ".jpeg" ) || file_name.endsWith( ".png" )
2669 || file_name.endsWith( ".gif" ) || file_name.endsWith( ".bmp" ) || f.isDirectory();
2673 public String getDescription() {
2674 return "Image files (*.jpg, *.jpeg, *.png, *.gif, *.bmp)";
2678 class MsaFileFilter extends FileFilter {
2681 public boolean accept( final File f ) {
2682 final String file_name = f.getName().trim().toLowerCase();
2683 return file_name.endsWith( ".msa" ) || file_name.endsWith( ".aln" ) || file_name.endsWith( ".fasta" )
2684 || file_name.endsWith( ".fas" ) || file_name.endsWith( ".fa" ) || f.isDirectory();
2688 public String getDescription() {
2689 return "Multiple sequence alignment files (*.msa, *.aln, *.fasta, *.fa, *.fas)";
2693 class NexusFilter extends FileFilter {
2696 public boolean accept( final File f ) {
2697 final String file_name = f.getName().trim().toLowerCase();
2698 return file_name.endsWith( ".nex" ) || file_name.endsWith( ".nexus" ) || file_name.endsWith( ".nx" )
2699 || file_name.endsWith( ".tre" ) || f.isDirectory();
2703 public String getDescription() {
2704 return "Nexus files (*.nex, *.nexus, *.nx, *.tre)";
2708 class NHFilter extends FileFilter {
2711 public boolean accept( final File f ) {
2712 final String file_name = f.getName().trim().toLowerCase();
2713 return file_name.endsWith( ".nh" ) || file_name.endsWith( ".newick" ) || file_name.endsWith( ".phy" )
2714 || file_name.endsWith( ".tr" ) || file_name.endsWith( ".tree" ) || file_name.endsWith( ".dnd" )
2715 || file_name.endsWith( ".ph" ) || file_name.endsWith( ".phb" ) || file_name.endsWith( ".nwk" )
2720 public String getDescription() {
2721 return "New Hampshire - Newick files (*.nh, *.newick, *.phy, *.tree, *.dnd, *.tr, *.ph, *.phb, *.nwk)";
2725 class NHXFilter extends FileFilter {
2728 public boolean accept( final File f ) {
2729 final String file_name = f.getName().trim().toLowerCase();
2730 return file_name.endsWith( ".nhx" ) || f.isDirectory();
2734 public String getDescription() {
2735 return "NHX files (*.nhx) [deprecated]";
2739 class PdfFilter extends FileFilter {
2742 public boolean accept( final File f ) {
2743 return f.getName().trim().toLowerCase().endsWith( ".pdf" ) || f.isDirectory();
2747 public String getDescription() {
2748 return "PDF files (*.pdf)";
2752 class SequencesFileFilter extends FileFilter {
2755 public boolean accept( final File f ) {
2756 final String file_name = f.getName().trim().toLowerCase();
2757 return file_name.endsWith( ".fasta" ) || file_name.endsWith( ".fa" ) || file_name.endsWith( ".fas" )
2758 || file_name.endsWith( ".seqs" ) || f.isDirectory();
2762 public String getDescription() {
2763 return "Sequences files (*.fasta, *.fa, *.fas, *.seqs )";
2767 class TolFilter extends FileFilter {
2770 public boolean accept( final File f ) {
2771 final String file_name = f.getName().trim().toLowerCase();
2772 return ( file_name.endsWith( ".tol" ) || file_name.endsWith( ".tolxml" ) || file_name.endsWith( ".zip" ) || f
2773 .isDirectory() ) && ( !file_name.endsWith( ".xml.zip" ) );
2777 public String getDescription() {
2778 return "Tree of Life files (*.tol, *.tolxml)";
2782 class XMLFilter extends FileFilter {
2785 public boolean accept( final File f ) {
2786 final String file_name = f.getName().trim().toLowerCase();
2787 return file_name.endsWith( ".xml" ) || file_name.endsWith( ".phyloxml" ) || file_name.endsWith( "phylo.xml" )
2788 || file_name.endsWith( ".pxml" ) || file_name.endsWith( ".zip" ) || f.isDirectory();
2792 public String getDescription() {
2793 return "phyloXML files (*.xml, *.phyloxml, *phylo.xml, *.pxml, *.zip)";