int => long for node id
[jalview.git] / forester / java / src / org / forester / archaeopteryx / MainFrame.java
1 // $Id:
2 // FORESTER -- software libraries and applications
3 // for evolutionary biology research and applications.
4 //
5 // Copyright (C) 2008-2010 Christian M. Zmasek
6 // All rights reserved
7 //
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.
12 //
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.
17 //
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
21 //
22 // Contact: phylosoft @ gmail . com
23 // WWW: https://sites.google.com/site/cmzmasek/home/software/forester
24
25 package org.forester.archaeopteryx;
26
27 import java.awt.Color;
28 import java.awt.Component;
29 import java.awt.Container;
30 import java.awt.Font;
31 import java.awt.event.ActionEvent;
32 import java.awt.event.ActionListener;
33 import java.io.IOException;
34 import java.util.LinkedList;
35 import java.util.List;
36 import java.util.Locale;
37 import java.util.Map;
38 import java.util.NoSuchElementException;
39 import java.util.Set;
40
41 import javax.swing.Box;
42 import javax.swing.JApplet;
43 import javax.swing.JCheckBoxMenuItem;
44 import javax.swing.JFrame;
45 import javax.swing.JLabel;
46 import javax.swing.JMenu;
47 import javax.swing.JMenuBar;
48 import javax.swing.JMenuItem;
49 import javax.swing.JOptionPane;
50 import javax.swing.JPanel;
51 import javax.swing.JRadioButtonMenuItem;
52 import javax.swing.JTextField;
53 import javax.swing.SwingUtilities;
54
55 import org.forester.archaeopteryx.Options.CLADOGRAM_TYPE;
56 import org.forester.archaeopteryx.Options.NODE_LABEL_DIRECTION;
57 import org.forester.archaeopteryx.Options.PHYLOGENY_GRAPHICS_TYPE;
58 import org.forester.archaeopteryx.tools.InferenceManager;
59 import org.forester.archaeopteryx.tools.ProcessPool;
60 import org.forester.archaeopteryx.tools.ProcessRunning;
61 import org.forester.io.parsers.nhx.NHXParser.TAXONOMY_EXTRACTION;
62 import org.forester.phylogeny.Phylogeny;
63 import org.forester.phylogeny.PhylogenyNode;
64 import org.forester.phylogeny.PhylogenyNode.NH_CONVERSION_SUPPORT_VALUE_STYLE;
65 import org.forester.phylogeny.data.Annotation;
66 import org.forester.phylogeny.data.NodeVisualization.NodeFill;
67 import org.forester.phylogeny.data.NodeVisualization.NodeShape;
68 import org.forester.util.ForesterConstants;
69 import org.forester.util.ForesterUtil;
70
71 public abstract class MainFrame extends JFrame implements ActionListener {
72
73     static final String         USE_MOUSEWHEEL_SHIFT_TO_ROTATE          = "In this display type, use mousewheel + Shift to rotate [or A and S]";
74     static final String         PHYLOXML_REF_TOOL_TIP                   = Constants.PHYLOXML_REFERENCE;                                                                                                                                       //TODO //FIXME
75     static final String         APTX_REF_TOOL_TIP                       = Constants.APTX_REFERENCE;
76     private static final long   serialVersionUID                        = 3655000897845508358L;
77     final static Font           menu_font                               = new Font( Configuration.getDefaultFontFamilyName(),
78                                                                                     Font.PLAIN,
79                                                                                     10 );
80     static final String         TYPE_MENU_HEADER                        = "Type";
81     static final String         RECTANGULAR_TYPE_CBMI_LABEL             = "Rectangular";
82     static final String         EURO_TYPE_CBMI_LABEL                    = "Euro Type";
83     static final String         CURVED_TYPE_CBMI_LABEL                  = "Curved";
84     static final String         TRIANGULAR_TYPE_CBMI_LABEL              = "Triangular";
85     static final String         CONVEX_TYPE_CBMI_LABEL                  = "Convex";
86     static final String         ROUNDED_TYPE_CBMI_LABEL                 = "Rounded";
87     static final String         UNROOTED_TYPE_CBMI_LABEL                = "Unrooted (alpha)";                                                                                                                                                 //TODO
88     static final String         CIRCULAR_TYPE_CBMI_LABEL                = "Circular (alpha)";                                                                                                                                                 //TODO
89     static final String         OPTIONS_HEADER                          = "Options";
90     static final String         SEARCH_SUBHEADER                        = "Search:";
91     static final String         DISPLAY_SUBHEADER                       = "Display:";
92     static final String         SEARCH_TERMS_ONLY_LABEL                 = "Match Complete Terms Only";
93     static final String         SEARCH_CASE_SENSITIVE_LABEL             = "Case Sensitive";
94     static final String         INVERSE_SEARCH_RESULT_LABEL             = "Negate Result";
95     static final String         DISPLAY_BRANCH_LENGTH_VALUES_LABEL      = "Display Branch Length Values";
96     static final String         DISPLAY_SCALE_LABEL                     = "Display Scale";
97     static final String         NON_LINED_UP_CLADOGRAMS_LABEL           = "Non-Lined Up Cladograms";
98     static final String         UNIFORM_CLADOGRAMS_LABEL                = "Total Node Sum Dependent Cladograms";
99     static final String         LABEL_DIRECTION_LABEL                   = "Radial Labels";
100     static final String         LABEL_DIRECTION_TIP                     = "To use radial node labels in radial and unrooted display types";
101     static final String         SCREEN_ANTIALIAS_LABEL                  = "Antialias";
102     static final String         COLOR_LABELS_LABEL                      = "Colorize Labels Same as Parent Branch";
103     static final String         BG_GRAD_LABEL                           = "Background Color Gradient";
104     static final String         DISPLAY_NODE_BOXES_LABEL_EXT            = "Show External Node Shapes";
105     static final String         DISPLAY_NODE_BOXES_LABEL_INT            = "Show Internal Node Shapes";
106     static final String         SHOW_OVERVIEW_LABEL                     = "Show Overview";
107     static final String         FONT_SIZE_MENU_LABEL                    = "Font Size";
108     static final String         NONUNIFORM_CLADOGRAMS_LABEL             = "External Node Sum Dependent Cladograms";
109     static final String         SHOW_DOMAIN_LABELS_LABEL                = "Show Domain Labels";
110     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";
111     static final String         ABBREV_SN_LABEL                         = "Abbreviate Scientific Taxonomic Names";
112     static final String         TAXONOMY_COLORIZE_NODE_SHAPES_LABEL     = "Colorize Node Shapes According to Taxonomy";
113     static final String         CYCLE_NODE_SHAPE_LABEL                  = "Cycle Node Shapes";
114     static final String         CYCLE_NODE_FILL_LABEL                   = "Cycle Node Fill Type";
115     static final String         CHOOSE_NODE_SIZE_LABEL                  = "Choose Node Shape Size";
116     static final String         SHOW_CONF_STDDEV_LABEL                  = "Show Confidence Standard Deviations";
117     static final String         USE_BRACKETS_FOR_CONF_IN_NH_LABEL       = "Use Brackets for Confidence Values";
118     static final String         USE_INTERNAL_NAMES_FOR_CONF_IN_NH_LABEL = "Use Internal Node Names for Confidence Values";
119     JMenuBar                    _jmenubar;
120     JMenu                       _file_jmenu;
121     JMenu                       _tools_menu;
122     JMenu                       _view_jmenu;
123     JMenu                       _options_jmenu;
124     JMenu                       _font_size_menu;
125     JMenu                       _help_jmenu;
126     JMenuItem[]                 _load_phylogeny_from_webservice_menu_items;
127     // file menu:
128     JMenuItem                   _open_item;
129     JMenuItem                   _open_url_item;
130     JMenuItem                   _save_item;
131     JMenuItem                   _save_all_item;
132     JMenuItem                   _close_item;
133     JMenuItem                   _exit_item;
134     JMenuItem                   _new_item;
135     // tools menu:
136     JMenuItem                   _midpoint_root_item;
137     JMenuItem                   _taxcolor_item;
138     JMenuItem                   _confcolor_item;
139     JMenuItem                   _color_rank_jmi;
140     JMenuItem                   _collapse_species_specific_subtrees;
141     JMenuItem                   _collapse_below_threshold;                                                                                                                                                                                    //TODO implememt me
142     JMenuItem                   _obtain_detailed_taxonomic_information_jmi;
143     JMenuItem                   _obtain_detailed_taxonomic_information_deleting_jmi;
144     JMenuItem                   _obtain_seq_information_jmi;
145     JMenuItem                   _move_node_names_to_tax_sn_jmi;
146     JMenuItem                   _move_node_names_to_seq_names_jmi;
147     JMenuItem                   _extract_tax_code_from_node_names_jmi;
148     JMenuItem                   _annotate_item;
149     // font size menu:
150     JMenuItem                   _super_tiny_fonts_item;
151     JMenuItem                   _tiny_fonts_item;
152     JMenuItem                   _small_fonts_item;
153     JMenuItem                   _medium_fonts_item;
154     JMenuItem                   _large_fonts_item;
155     // options menu:
156     // _  screen and print
157     JMenuItem                   _choose_font_mi;
158     JMenuItem                   _switch_colors_mi;
159     JCheckBoxMenuItem           _label_direction_cbmi;
160     // _  screen display
161     JCheckBoxMenuItem           _screen_antialias_cbmi;
162     JCheckBoxMenuItem           _background_gradient_cbmi;
163     JRadioButtonMenuItem        _non_lined_up_cladograms_rbmi;
164     JRadioButtonMenuItem        _uniform_cladograms_rbmi;
165     JRadioButtonMenuItem        _ext_node_dependent_cladogram_rbmi;
166     JCheckBoxMenuItem           _show_branch_length_values_cbmi;
167     JCheckBoxMenuItem           _show_scale_cbmi;                                                                                                                                                                                             //TODO fix me
168     JCheckBoxMenuItem           _show_overview_cbmi;
169     JCheckBoxMenuItem           _show_domain_labels;
170     JCheckBoxMenuItem           _abbreviate_scientific_names;
171     JCheckBoxMenuItem           _color_labels_same_as_parent_branch;
172     JMenuItem                   _overview_placment_mi;
173     JMenuItem                   _choose_minimal_confidence_mi;
174     JCheckBoxMenuItem           _show_default_node_shapes_internal_cbmi;
175     JCheckBoxMenuItem           _show_default_node_shapes_external_cbmi;
176     JMenuItem                   _cycle_node_shape_mi;
177     JMenuItem                   _cycle_node_fill_mi;
178     JMenuItem                   _choose_node_size_mi;
179     JCheckBoxMenuItem           _taxonomy_colorize_node_shapes_cbmi;
180     JCheckBoxMenuItem           _show_confidence_stddev_cbmi;
181     // _  print
182     JCheckBoxMenuItem           _graphics_export_visible_only_cbmi;
183     JCheckBoxMenuItem           _antialias_print_cbmi;
184     JCheckBoxMenuItem           _print_black_and_white_cbmi;
185     JCheckBoxMenuItem           _print_using_actual_size_cbmi;
186     JCheckBoxMenuItem           _graphics_export_using_actual_size_cbmi;
187     JMenuItem                   _print_size_mi;
188     JMenuItem                   _choose_pdf_width_mi;
189     // _  parsing
190     JCheckBoxMenuItem           _internal_number_are_confidence_for_nh_parsing_cbmi;
191     JRadioButtonMenuItem        _extract_taxonomy_no_rbmi;
192     JRadioButtonMenuItem        _extract_taxonomy_yes_rbmi;
193     JRadioButtonMenuItem        _extract_taxonomy_pfam_rbmi;
194     JCheckBoxMenuItem           _replace_underscores_cbmi;
195     JCheckBoxMenuItem           _use_brackets_for_conf_in_nh_export_cbmi;
196     JCheckBoxMenuItem           _use_internal_names_for_conf_in_nh_export_cbmi;
197     // _  search
198     JCheckBoxMenuItem           _search_case_senstive_cbmi;
199     JCheckBoxMenuItem           _search_whole_words_only_cbmi;
200     JCheckBoxMenuItem           _inverse_search_result_cbmi;
201     // type menu:
202     JMenu                       _type_menu;
203     JCheckBoxMenuItem           _rectangular_type_cbmi;
204     JCheckBoxMenuItem           _triangular_type_cbmi;
205     JCheckBoxMenuItem           _curved_type_cbmi;
206     JCheckBoxMenuItem           _convex_type_cbmi;
207     JCheckBoxMenuItem           _euro_type_cbmi;
208     JCheckBoxMenuItem           _rounded_type_cbmi;
209     JCheckBoxMenuItem           _unrooted_type_cbmi;
210     JCheckBoxMenuItem           _circular_type_cbmi;
211     // view as text menu:
212     JMenuItem                   _view_as_NH_item;
213     JMenuItem                   _view_as_XML_item;
214     JMenuItem                   _view_as_nexus_item;
215     JMenuItem                   _display_basic_information_item;
216     // help menu:
217     JMenuItem                   _about_item;
218     JMenuItem                   _help_item;
219     JMenuItem                   _website_item;
220     JMenuItem                   _phyloxml_website_item;
221     JMenuItem                   _phyloxml_ref_item;
222     JMenuItem                   _aptx_ref_item;
223     // process menu:
224     JMenu                       _process_menu;
225     // Handy pointers to child components:
226     MainPanel                   _mainpanel;
227     Container                   _contentpane;
228     final LinkedList<TextFrame> _textframes                             = new LinkedList<TextFrame>();                                                                                                                                         ;
229     Configuration               _configuration;
230     JMenuItem                   _remove_branch_color_item;
231     Options                     _options;
232     InferenceManager            _inference_manager;
233     final ProcessPool           _process_pool;
234     private String              _previous_node_annotation_ref;
235
236     MainFrame() {
237         _process_pool = ProcessPool.createInstance();
238     }
239
240     /**
241      * Action performed.
242      */
243     @Override
244     public void actionPerformed( final ActionEvent e ) {
245         final Object o = e.getSource();
246         boolean is_applet = false;
247         JApplet applet = null;
248         if ( getCurrentTreePanel() != null ) {
249             is_applet = getCurrentTreePanel().isApplet();
250             if ( is_applet ) {
251                 applet = getCurrentTreePanel().obtainApplet();
252             }
253         }
254         if ( o == _open_url_item ) {
255             readPhylogeniesFromURL();
256         }
257         else if ( o == _exit_item ) {
258             close();
259         }
260         else if ( o == _taxcolor_item ) {
261             taxColor();
262         }
263         else if ( o == _confcolor_item ) {
264             confColor();
265         }
266         else if ( o == _color_rank_jmi ) {
267             colorRank();
268         }
269         else if ( o == _collapse_species_specific_subtrees ) {
270             if ( isSubtreeDisplayed() ) {
271                 return;
272             }
273             if ( getCurrentTreePanel() != null ) {
274                 getCurrentTreePanel().collapseSpeciesSpecificSubtrees();
275             }
276         }
277         else if ( o == _remove_branch_color_item ) {
278             if ( isSubtreeDisplayed() ) {
279                 return;
280             }
281             removeBranchColors();
282         }
283         else if ( o == _midpoint_root_item ) {
284             if ( isSubtreeDisplayed() ) {
285                 return;
286             }
287             midpointRoot();
288         }
289         else if ( o == _annotate_item ) {
290             annotateSequences();
291         }
292         else if ( o == _switch_colors_mi ) {
293             switchColors();
294         }
295         else if ( o == _display_basic_information_item ) {
296             displayBasicInformation();
297         }
298         else if ( o == _view_as_NH_item ) {
299             viewAsNH();
300         }
301         else if ( o == _view_as_XML_item ) {
302             viewAsXML();
303         }
304         else if ( o == _view_as_nexus_item ) {
305             viewAsNexus();
306         }
307         else if ( o == _super_tiny_fonts_item ) {
308             if ( getCurrentTreePanel() != null ) {
309                 getCurrentTreePanel().setSuperTinyFonts();
310                 getCurrentTreePanel().repaint();
311             }
312         }
313         else if ( o == _tiny_fonts_item ) {
314             if ( getCurrentTreePanel() != null ) {
315                 getCurrentTreePanel().setTinyFonts();
316                 getCurrentTreePanel().repaint();
317             }
318         }
319         else if ( o == _small_fonts_item ) {
320             if ( getCurrentTreePanel() != null ) {
321                 getCurrentTreePanel().setSmallFonts();
322                 getCurrentTreePanel().repaint();
323             }
324         }
325         else if ( o == _medium_fonts_item ) {
326             if ( getCurrentTreePanel() != null ) {
327                 getCurrentTreePanel().setMediumFonts();
328                 getCurrentTreePanel().repaint();
329             }
330         }
331         else if ( o == _large_fonts_item ) {
332             if ( getCurrentTreePanel() != null ) {
333                 getCurrentTreePanel().setLargeFonts();
334                 getCurrentTreePanel().repaint();
335             }
336         }
337         else if ( o == _choose_font_mi ) {
338             chooseFont();
339         }
340         else if ( o == _choose_minimal_confidence_mi ) {
341             chooseMinimalConfidence();
342         }
343         else if ( o == _choose_node_size_mi ) {
344             chooseNodeSize( getOptions(), this );
345         }
346         else if ( o == _overview_placment_mi ) {
347             MainFrame.cycleOverview( getOptions(), getCurrentTreePanel() );
348         }
349         else if ( o == _cycle_node_fill_mi ) {
350             MainFrame.cycleNodeFill( getOptions(), getCurrentTreePanel() );
351         }
352         else if ( o == _cycle_node_shape_mi ) {
353             MainFrame.cycleNodeShape( getOptions(), getCurrentTreePanel() );
354         }
355         else if ( o == _screen_antialias_cbmi ) {
356             updateOptions( getOptions() );
357             updateScreenTextAntialias( getMainPanel().getTreePanels() );
358         }
359         else if ( o == _background_gradient_cbmi ) {
360             updateOptions( getOptions() );
361         }
362         else if ( o == _show_domain_labels ) {
363             updateOptions( getOptions() );
364         }
365         else if ( o == _abbreviate_scientific_names ) {
366             updateOptions( getOptions() );
367         }
368         else if ( o == _color_labels_same_as_parent_branch ) {
369             updateOptions( getOptions() );
370         }
371         else if ( o == _show_default_node_shapes_internal_cbmi ) {
372             updateOptions( getOptions() );
373         }
374         else if ( o == _show_default_node_shapes_external_cbmi ) {
375             updateOptions( getOptions() );
376         }
377         else if ( o == _taxonomy_colorize_node_shapes_cbmi ) {
378             updateOptions( getOptions() );
379         }
380         else if ( o == _non_lined_up_cladograms_rbmi ) {
381             updateOptions( getOptions() );
382             showWhole();
383         }
384         else if ( o == _uniform_cladograms_rbmi ) {
385             updateOptions( getOptions() );
386             showWhole();
387         }
388         else if ( o == _ext_node_dependent_cladogram_rbmi ) {
389             updateOptions( getOptions() );
390             showWhole();
391         }
392         else if ( o == _search_case_senstive_cbmi ) {
393             updateOptions( getOptions() );
394             getMainPanel().getControlPanel().search();
395         }
396         else if ( o == _search_whole_words_only_cbmi ) {
397             updateOptions( getOptions() );
398             getMainPanel().getControlPanel().search();
399         }
400         else if ( o == _inverse_search_result_cbmi ) {
401             updateOptions( getOptions() );
402             getMainPanel().getControlPanel().search();
403         }
404         else if ( o == _show_scale_cbmi ) {
405             updateOptions( getOptions() );
406         }
407         else if ( o == _show_branch_length_values_cbmi ) {
408             updateOptions( getOptions() );
409         }
410         else if ( o == _show_confidence_stddev_cbmi ) {
411             updateOptions( getOptions() );
412         }
413         else if ( o == _use_brackets_for_conf_in_nh_export_cbmi ) {
414             if ( _use_brackets_for_conf_in_nh_export_cbmi.isSelected() ) {
415                 _use_internal_names_for_conf_in_nh_export_cbmi.setSelected( false );
416             }
417             updateOptions( getOptions() );
418         }
419         else if ( o == _use_internal_names_for_conf_in_nh_export_cbmi ) {
420             if ( _use_internal_names_for_conf_in_nh_export_cbmi.isSelected() ) {
421                 _use_brackets_for_conf_in_nh_export_cbmi.setSelected( false );
422             }
423             updateOptions( getOptions() );
424         }
425         else if ( o == _label_direction_cbmi ) {
426             updateOptions( getOptions() );
427         }
428         else if ( o == _show_overview_cbmi ) {
429             updateOptions( getOptions() );
430             if ( getCurrentTreePanel() != null ) {
431                 getCurrentTreePanel().updateOvSizes();
432             }
433         }
434         else if ( ( o == _rectangular_type_cbmi ) || ( o == _triangular_type_cbmi ) || ( o == _curved_type_cbmi )
435                 || ( o == _convex_type_cbmi ) || ( o == _euro_type_cbmi ) || ( o == _rounded_type_cbmi )
436                 || ( o == _unrooted_type_cbmi ) || ( o == _circular_type_cbmi ) ) {
437             typeChanged( o );
438         }
439         else if ( o == _about_item ) {
440             about();
441         }
442         else if ( o == _help_item ) {
443             help( getConfiguration().getWebLinks() );
444         }
445         else if ( o == _website_item ) {
446             try {
447                 AptxUtil.openWebsite( Constants.APTX_WEB_SITE, is_applet, applet );
448             }
449             catch ( final IOException e1 ) {
450                 ForesterUtil.printErrorMessage( Constants.PRG_NAME, e1.toString() );
451             }
452         }
453         else if ( o == _phyloxml_website_item ) {
454             try {
455                 AptxUtil.openWebsite( Constants.PHYLOXML_WEB_SITE, is_applet, applet );
456             }
457             catch ( final IOException e1 ) {
458                 ForesterUtil.printErrorMessage( Constants.PRG_NAME, e1.toString() );
459             }
460         }
461         else if ( o == _aptx_ref_item ) {
462             try {
463                 AptxUtil.openWebsite( Constants.APTX_REFERENCE_URL, is_applet, applet );
464             }
465             catch ( final IOException e1 ) {
466                 ForesterUtil.printErrorMessage( Constants.PRG_NAME, e1.toString() );
467             }
468         }
469         else if ( o == _phyloxml_ref_item ) {
470             try {
471                 AptxUtil.openWebsite( Constants.PHYLOXML_REFERENCE_URL, is_applet, applet );
472             }
473             catch ( final IOException e1 ) {
474                 ForesterUtil.printErrorMessage( Constants.PRG_NAME, e1.toString() );
475             }
476         }
477         else {
478             if ( _load_phylogeny_from_webservice_menu_items != null ) {
479                 for( int i = 0; i < _load_phylogeny_from_webservice_menu_items.length; ++i ) {
480                     if ( o == _load_phylogeny_from_webservice_menu_items[ i ] ) {
481                         readPhylogeniesFromWebservice( i );
482                     }
483                 }
484             }
485         }
486         _contentpane.repaint();
487     }
488
489     public Configuration getConfiguration() {
490         return _configuration;
491     }
492
493     /**
494      * This method returns the current external node data which
495      * has been selected by the user by clicking the "Return ..."
496      * menu item. This method is expected to be called from Javascript or
497      * something like it.
498      * 
499      * @return current external node data as String
500      */
501     public String getCurrentExternalNodesDataBuffer() {
502         return getCurrentTreePanel().getCurrentExternalNodesDataBufferAsString();
503     }
504
505     public int getCurrentExternalNodesDataBufferChangeCounter() {
506         return getCurrentTreePanel().getCurrentExternalNodesDataBufferChangeCounter();
507     }
508
509     public int getCurrentExternalNodesDataBufferLength() {
510         return getCurrentTreePanel().getCurrentExternalNodesDataBufferAsString().length();
511     }
512
513     public InferenceManager getInferenceManager() {
514         return _inference_manager;
515     }
516
517     public MainPanel getMainPanel() {
518         return _mainpanel;
519     }
520
521     public Options getOptions() {
522         return _options;
523     }
524
525     public ProcessPool getProcessPool() {
526         return _process_pool;
527     }
528
529     public void showTextFrame( final String s, final String title ) {
530         checkTextFrames();
531         _textframes.addLast( TextFrame.instantiate( s, title, _textframes ) );
532     }
533
534     public void showWhole() {
535         _mainpanel.getControlPanel().showWhole();
536     }
537
538     public void updateProcessMenu() {
539         // In general Swing is not thread safe.
540         // See "Swing's Threading Policy".
541         SwingUtilities.invokeLater( new Runnable() {
542
543             @Override
544             public void run() {
545                 doUpdateProcessMenu();
546             }
547         } );
548     }
549
550     void activateSaveAllIfNeeded() {
551         if ( ( getMainPanel().getTabbedPane() != null ) && ( getMainPanel().getTabbedPane().getTabCount() > 1 ) ) {
552             _save_all_item.setEnabled( true );
553         }
554         else {
555             _save_all_item.setEnabled( false );
556         }
557     }
558
559     void buildFileMenu() {
560         _file_jmenu = createMenu( "File", getConfiguration() );
561         _file_jmenu.add( _open_url_item = new JMenuItem( "Read tree from URL/webservice..." ) );
562         _file_jmenu.addSeparator();
563         _file_jmenu.add( _exit_item = new JMenuItem( "Exit" ) );
564         customizeJMenuItem( _open_url_item );
565         customizeJMenuItem( _exit_item );
566         _jmenubar.add( _file_jmenu );
567     }
568
569     void buildFontSizeMenu() {
570         _font_size_menu = createMenu( FONT_SIZE_MENU_LABEL, getConfiguration() );
571         _font_size_menu.add( _super_tiny_fonts_item = new JMenuItem( "Super Tiny Fonts" ) );
572         _font_size_menu.add( _tiny_fonts_item = new JMenuItem( "Tiny Fonts" ) );
573         _font_size_menu.add( _small_fonts_item = new JMenuItem( "Small Fonts" ) );
574         _font_size_menu.add( _medium_fonts_item = new JMenuItem( "Medium Fonts" ) );
575         _font_size_menu.add( _large_fonts_item = new JMenuItem( "Large Fonts" ) );
576         customizeJMenuItem( _super_tiny_fonts_item );
577         customizeJMenuItem( _tiny_fonts_item );
578         customizeJMenuItem( _small_fonts_item );
579         customizeJMenuItem( _medium_fonts_item );
580         customizeJMenuItem( _large_fonts_item );
581         _jmenubar.add( _font_size_menu );
582     }
583
584     void buildHelpMenu() {
585         _help_jmenu = createMenu( "Help", getConfiguration() );
586         _help_jmenu.add( _help_item = new JMenuItem( "Help" ) );
587         _help_jmenu.add( _website_item = new JMenuItem( "Archaeopteryx Home" ) );
588         _aptx_ref_item = new JMenuItem( "Archaeopteryx Reference" );
589         _help_jmenu.add( _phyloxml_website_item = new JMenuItem( "phyloXML Home" ) );
590         _help_jmenu.add( _phyloxml_ref_item = new JMenuItem( "phyloXML Reference" ) );
591         _help_jmenu.addSeparator();
592         _help_jmenu.add( _about_item = new JMenuItem( "About" ) );
593         customizeJMenuItem( _help_item );
594         customizeJMenuItem( _website_item );
595         customizeJMenuItem( _phyloxml_website_item );
596         customizeJMenuItem( _aptx_ref_item );
597         customizeJMenuItem( _phyloxml_ref_item );
598         customizeJMenuItem( _about_item );
599         _phyloxml_ref_item.setToolTipText( PHYLOXML_REF_TOOL_TIP );
600         _aptx_ref_item.setToolTipText( APTX_REF_TOOL_TIP );
601         _jmenubar.add( _help_jmenu );
602     }
603
604     void buildTypeMenu() {
605         _type_menu = createMenu( TYPE_MENU_HEADER, getConfiguration() );
606         _type_menu.add( _rectangular_type_cbmi = new JCheckBoxMenuItem( MainFrame.RECTANGULAR_TYPE_CBMI_LABEL ) );
607         _type_menu.add( _euro_type_cbmi = new JCheckBoxMenuItem( MainFrame.EURO_TYPE_CBMI_LABEL ) );
608         _type_menu.add( _rounded_type_cbmi = new JCheckBoxMenuItem( MainFrame.ROUNDED_TYPE_CBMI_LABEL ) );
609         _type_menu.add( _curved_type_cbmi = new JCheckBoxMenuItem( MainFrame.CURVED_TYPE_CBMI_LABEL ) );
610         _type_menu.add( _triangular_type_cbmi = new JCheckBoxMenuItem( MainFrame.TRIANGULAR_TYPE_CBMI_LABEL ) );
611         _type_menu.add( _convex_type_cbmi = new JCheckBoxMenuItem( MainFrame.CONVEX_TYPE_CBMI_LABEL ) );
612         _type_menu.add( _unrooted_type_cbmi = new JCheckBoxMenuItem( MainFrame.UNROOTED_TYPE_CBMI_LABEL ) );
613         _type_menu.add( _circular_type_cbmi = new JCheckBoxMenuItem( MainFrame.CIRCULAR_TYPE_CBMI_LABEL ) );
614         customizeCheckBoxMenuItem( _rectangular_type_cbmi, false );
615         customizeCheckBoxMenuItem( _triangular_type_cbmi, false );
616         customizeCheckBoxMenuItem( _euro_type_cbmi, false );
617         customizeCheckBoxMenuItem( _rounded_type_cbmi, false );
618         customizeCheckBoxMenuItem( _curved_type_cbmi, false );
619         customizeCheckBoxMenuItem( _convex_type_cbmi, false );
620         customizeCheckBoxMenuItem( _unrooted_type_cbmi, false );
621         customizeCheckBoxMenuItem( _circular_type_cbmi, false );
622         _unrooted_type_cbmi.setToolTipText( MainFrame.USE_MOUSEWHEEL_SHIFT_TO_ROTATE );
623         _circular_type_cbmi.setToolTipText( MainFrame.USE_MOUSEWHEEL_SHIFT_TO_ROTATE );
624         initializeTypeMenu( getOptions() );
625         _jmenubar.add( _type_menu );
626     }
627
628     void buildViewMenu() {
629         _view_jmenu = createMenu( "View", getConfiguration() );
630         _view_jmenu.add( _display_basic_information_item = new JMenuItem( "Display Basic Information" ) );
631         _view_jmenu.addSeparator();
632         _view_jmenu.add( _view_as_XML_item = new JMenuItem( "View as phyloXML" ) );
633         _view_jmenu.add( _view_as_NH_item = new JMenuItem( "View as Newick" ) );
634         _view_jmenu.add( _view_as_nexus_item = new JMenuItem( "View as Nexus" ) );
635         customizeJMenuItem( _display_basic_information_item );
636         customizeJMenuItem( _view_as_NH_item );
637         customizeJMenuItem( _view_as_XML_item );
638         customizeJMenuItem( _view_as_nexus_item );
639         _jmenubar.add( _view_jmenu );
640     }
641
642     void checkTextFrames() {
643         if ( _textframes.size() > 5 ) {
644             try {
645                 if ( _textframes.getFirst() != null ) {
646                     _textframes.getFirst().removeMe();
647                 }
648                 else {
649                     _textframes.removeFirst();
650                 }
651             }
652             catch ( final NoSuchElementException e ) {
653                 // Ignore.
654             }
655         }
656     }
657
658     void close() {
659         removeAllTextFrames();
660         if ( _mainpanel != null ) {
661             _mainpanel.terminate();
662         }
663         if ( _contentpane != null ) {
664             _contentpane.removeAll();
665         }
666         setVisible( false );
667         dispose();
668     }
669
670     void colorRank() {
671         if ( _mainpanel.getCurrentTreePanel() != null ) {
672             final String[] ranks = AptxUtil.getAllPossibleRanks();
673             final String rank = ( String ) JOptionPane
674                     .showInputDialog( this,
675                                       "What rank should the colorization be based on",
676                                       "Rank Selection",
677                                       JOptionPane.QUESTION_MESSAGE,
678                                       null,
679                                       ranks,
680                                       null );
681             if ( !ForesterUtil.isEmpty( rank ) ) {
682                 _mainpanel.getCurrentTreePanel().colorRank( rank );
683             }
684         }
685     }
686
687     void confColor() {
688         if ( _mainpanel.getCurrentTreePanel() != null ) {
689             _mainpanel.getCurrentTreePanel().confColor();
690         }
691     }
692
693     void customizeCheckBoxMenuItem( final JCheckBoxMenuItem item, final boolean is_selected ) {
694         if ( item != null ) {
695             item.setFont( MainFrame.menu_font );
696             if ( !getConfiguration().isUseNativeUI() ) {
697                 item.setBackground( getConfiguration().getGuiMenuBackgroundColor() );
698                 item.setForeground( getConfiguration().getGuiMenuTextColor() );
699             }
700             item.setSelected( is_selected );
701             item.addActionListener( this );
702         }
703     }
704
705     JMenuItem customizeJMenuItem( final JMenuItem jmi ) {
706         if ( jmi != null ) {
707             jmi.setFont( MainFrame.menu_font );
708             if ( !getConfiguration().isUseNativeUI() ) {
709                 jmi.setBackground( getConfiguration().getGuiMenuBackgroundColor() );
710                 jmi.setForeground( getConfiguration().getGuiMenuTextColor() );
711             }
712             jmi.addActionListener( this );
713         }
714         return jmi;
715     }
716
717     void customizeRadioButtonMenuItem( final JRadioButtonMenuItem item, final boolean is_selected ) {
718         if ( item != null ) {
719             item.setFont( MainFrame.menu_font );
720             if ( !getConfiguration().isUseNativeUI() ) {
721                 item.setBackground( getConfiguration().getGuiMenuBackgroundColor() );
722                 item.setForeground( getConfiguration().getGuiMenuTextColor() );
723             }
724             item.setSelected( is_selected );
725             item.addActionListener( this );
726         }
727     }
728
729     void displayBasicInformation() {
730         if ( ( _mainpanel.getCurrentPhylogeny() != null ) && !_mainpanel.getCurrentPhylogeny().isEmpty() ) {
731             String title = "Basic Information";
732             if ( !ForesterUtil.isEmpty( _mainpanel.getCurrentPhylogeny().getName() ) ) {
733                 title = _mainpanel.getCurrentPhylogeny().getName() + " " + title;
734             }
735             showTextFrame( AptxUtil.createBasicInformation( _mainpanel.getCurrentPhylogeny() ), title );
736         }
737     }
738
739     void exceptionOccuredDuringOpenFile( final Exception e ) {
740         try {
741             _mainpanel.getCurrentTreePanel().setArrowCursor();
742         }
743         catch ( final Exception ex ) {
744             // Do nothing.
745         }
746         JOptionPane.showMessageDialog( this,
747                                        ForesterUtil.wordWrap( e.getLocalizedMessage(), 80 ),
748                                        "Error during File|Open",
749                                        JOptionPane.ERROR_MESSAGE );
750     }
751
752     void exceptionOccuredDuringSaveAs( final Exception e ) {
753         try {
754             _mainpanel.getCurrentTreePanel().setArrowCursor();
755         }
756         catch ( final Exception ex ) {
757             // Do nothing.
758         }
759         JOptionPane.showMessageDialog( this, "Exception" + e, "Error during File|SaveAs", JOptionPane.ERROR_MESSAGE );
760     }
761
762     boolean GAndSDoHaveMoreThanOneSpeciesInComman( final Phylogeny gene_tree ) {
763         if ( ( gene_tree == null ) || gene_tree.isEmpty() ) {
764             JOptionPane.showMessageDialog( this,
765                                            "Gene tree and species tree have no species in common.",
766                                            "Error during SDI",
767                                            JOptionPane.ERROR_MESSAGE );
768             return false;
769         }
770         else if ( gene_tree.getNumberOfExternalNodes() < 2 ) {
771             JOptionPane.showMessageDialog( this,
772                                            "Gene tree and species tree have only one species in common.",
773                                            "Error during SDI",
774                                            JOptionPane.ERROR_MESSAGE );
775             return false;
776         }
777         else {
778             return true;
779         }
780     }
781
782     TreePanel getCurrentTreePanel() {
783         return getMainPanel().getCurrentTreePanel();
784     }
785
786     JMenu getHelpMenu() {
787         return _help_jmenu;
788     }
789
790     JCheckBoxMenuItem getlabelDirectionCbmi() {
791         return _label_direction_cbmi;
792     }
793
794     JMenuBar getMenuBarOfMainFrame() {
795         return _jmenubar;
796     }
797
798     void help( final Map<String, WebLink> weblinks ) {
799         final StringBuilder sb = new StringBuilder();
800         sb.append( "Display options\n" );
801         sb.append( "-------------------\n" );
802         sb.append( "Use the checkboxes to select types of information to display on the tree.\n\n" );
803         sb.append( "Clickable tree nodes\n" );
804         sb.append( "--------------------\n" );
805         sb.append( "Tree nodes can be clicked, the action is determined by the 'click on node to' menu\n" );
806         sb.append( "or by right clicking:\n" );
807         sb.append( "o  Display Node Data -- display information for a node\n" );
808         sb.append( "o  Collapse/Uncollapse -- collapse and uncollapse subtree from clicked node\n" );
809         sb.append( "o  Root/Reroot -- change tree root to clicked node\n" );
810         sb.append( "o  Sub/Super Tree -- toggle between subtree from clicked node and whole tree\n" );
811         sb.append( "o  Swap Descendants -- switch descendant on either side of clicked node\n" );
812         sb.append( "o  Colorize Subtree -- color a subtree\n" );
813         sb.append( "o  Open Sequence Web -- launch a web browser to display sequence information\n" );
814         sb.append( "o  Open Taxonomy Web -- launch a web browser to display taxonomy information\n" );
815         sb.append( "-  there may be additional choices depending on this particular setup\n\n" );
816         sb.append( "Right clicking on a node always displays the information of a node.\n\n" );
817         sb.append( "Zooming\n" );
818         sb.append( "---------\n" );
819         sb.append( "The mouse wheel and the plus and minus keys control zooming.\n" );
820         sb.append( "Mouse wheel+Ctrl changes the text size.\n" );
821         sb.append( "Mouse wheel+Shift controls zooming in vertical direction only.\n" );
822         sb.append( "Use the buttons on the control panel to zoom the tree in and out, horizontally or vertically.\n" );
823         sb.append( "The entire tree can be fitted into the window by clicking the \"F\" button, or by pressing F, Delete, or Home.\n" );
824         sb.append( "The up, down, left, and right keys can be used to move the visible part (if zoomed in).\n" );
825         sb.append( "Up, down, left, and right+Shift can be used to control zooming horizontally and vertically.\n" );
826         sb.append( "Plus and minus keys+Ctrl change the text size; F+Ctrl, Delete+Ctrl, or Home+Ctrl resets it.\n\n" );
827         sb.append( "Quick tree manipulation:\n" );
828         sb.append( "------------------------\n" );
829         sb.append( "Order Subtrees -- order the tree by branch length\n" );
830         sb.append( "Uncollapse All -- uncollapse any and all collapsed branches\n\n" );
831         sb.append( "Memory problems (Java heap space error)\n" );
832         sb.append( "---------------------------------------\n" );
833         sb.append( "Since the Java default memory allocation is quite small, it might by necessary (for trees\n" );
834         sb.append( "with more than approximately 5000 external nodes) to increase the memory which Java can use, with\n" );
835         sb.append( "the '-Xmx' Java command line option. For example:\n" );
836         sb.append( "java -Xms32m -Xmx256m -cp path\\to\\forester.jar org.forester.archaeopteryx.Archaeopteryx\n\n" );
837         if ( ( weblinks != null ) && ( weblinks.size() > 0 ) ) {
838             sb.append( "Active web links\n" );
839             sb.append( "--------------------\n" );
840             for( final String key : weblinks.keySet() ) {
841                 sb.append( " " + weblinks.get( key ).toString() + "\n" );
842             }
843         }
844         // + "General remarks\n"
845         // + "---------------\n"
846         // +
847         // "o  The application version permits copying to the clipboard \n"
848         // +
849         // "    in the \"View\"|\"View as ...\" frame (either by control-c or button press).\n"
850         // +
851         // "o  Changes made to a subtree affect this subtree and its subtrees,\n"
852         // + "    but not any of its parent tree(s).\n"
853         // +
854         // "o  Archaeopteryx tries to detect whether the numerical values in a NH tree\n"
855         // +
856         // "    are likely to be bootstrap values instead of branch length values.\n\n"
857         // +
858         // " Remarks regarding SDI (Speciation Duplication Inference):\n"
859         // +
860         // "o  Each external node of the gene tree (in display) needs to be associated with\n"
861         // +
862         // "    a species: either directly through the \"Species\" field, or the species\n"
863         // +
864         // "    is part of the sequence name in the form \"XXXX_SPECIES\"\n"
865         // +
866         // "    (e.g. \"ACON_DROME\" or \"ACON_DROME/123-4489\" which is also acceptable).\n"
867         // +
868         // "o  A species tree for each species of the gene tree needs to be loaded with\n"
869         // +
870         // "   \"SDI\"|\"Load species tree\" prior the SDI execution.\n"
871         // +
872         // "o  !External nodes of the gene tree associated with species not present in\n"
873         // +
874         // "    the species tree are REMOVED prior to SDI execution!\n"
875         // +
876         // "o  Both the gene tree and the species tree must be completely binary.\n"
877         // +
878         // "o  Duplications and speciations are a function of the position of the root.\n"
879         // +
880         // "    Hence, after each manual \"Root/Reroot\"ing some duplications will be\n"
881         // + "    incorrect and need to be inferred again\n"
882         // +
883         // "    with: \"SDI\"|\"SDI (Speciation Duplication Inference)\n\n"
884         sb.append( "\n" );
885         sb.append( "phyloXML\n" );
886         sb.append( "-------------------\n" );
887         sb.append( "Reference: " + Constants.PHYLOXML_REFERENCE + "\n" );
888         sb.append( "Website: " + Constants.PHYLOXML_WEB_SITE + "\n" );
889         sb.append( "Version: " + ForesterConstants.PHYLO_XML_VERSION + "\n" );
890         sb.append( "\n" );
891         sb.append( "For more information: https://sites.google.com/site/cmzmasek/home/software/archaeopteryx\n" );
892         sb.append( "Email: " + Constants.AUTHOR_EMAIL + "\n\n" );
893         TextFrame.instantiate( sb.toString(), "Help", _textframes );
894     }
895
896     void initializeTypeMenu( final Options options ) {
897         setTypeMenuToAllUnselected();
898         switch ( options.getPhylogenyGraphicsType() ) {
899             case CONVEX:
900                 _convex_type_cbmi.setSelected( true );
901                 break;
902             case CURVED:
903                 _curved_type_cbmi.setSelected( true );
904                 break;
905             case EURO_STYLE:
906                 _euro_type_cbmi.setSelected( true );
907                 break;
908             case ROUNDED:
909                 _rounded_type_cbmi.setSelected( true );
910                 break;
911             case TRIANGULAR:
912                 _triangular_type_cbmi.setSelected( true );
913                 break;
914             case UNROOTED:
915                 _unrooted_type_cbmi.setSelected( true );
916                 break;
917             case CIRCULAR:
918                 _circular_type_cbmi.setSelected( true );
919                 break;
920             default:
921                 _rectangular_type_cbmi.setSelected( true );
922                 break;
923         }
924     }
925
926     boolean isSubtreeDisplayed() {
927         if ( getCurrentTreePanel() != null ) {
928             if ( getCurrentTreePanel().isCurrentTreeIsSubtree() ) {
929                 JOptionPane
930                         .showMessageDialog( this,
931                                             "This operation can only be performed on a complete tree, not on the currently displayed sub-tree only.",
932                                             "Operation can not be exectuted on a sub-tree",
933                                             JOptionPane.WARNING_MESSAGE );
934                 return true;
935             }
936         }
937         return false;
938     }
939
940     void midpointRoot() {
941         if ( _mainpanel.getCurrentTreePanel() != null ) {
942             _mainpanel.getCurrentTreePanel().midpointRoot();
943         }
944     }
945
946     abstract void readPhylogeniesFromURL();
947
948     void readPhylogeniesFromWebservice( final int i ) {
949         final UrlTreeReader reader = new UrlTreeReader( this, i );
950         new Thread( reader ).start();
951     }
952
953     void removeAllTextFrames() {
954         for( final TextFrame tf : _textframes ) {
955             if ( tf != null ) {
956                 tf.close();
957             }
958         }
959         _textframes.clear();
960     }
961
962     void setConfiguration( final Configuration configuration ) {
963         _configuration = configuration;
964     }
965
966     void setInferenceManager( final InferenceManager i ) {
967         _inference_manager = i;
968     }
969
970     void setOptions( final Options options ) {
971         _options = options;
972     }
973
974     void setSelectedTypeInTypeMenu( final PHYLOGENY_GRAPHICS_TYPE type ) {
975         setTypeMenuToAllUnselected();
976         switch ( type ) {
977             case CIRCULAR:
978                 _circular_type_cbmi.setSelected( true );
979                 break;
980             case CONVEX:
981                 _convex_type_cbmi.setSelected( true );
982                 break;
983             case CURVED:
984                 _curved_type_cbmi.setSelected( true );
985                 break;
986             case EURO_STYLE:
987                 _euro_type_cbmi.setSelected( true );
988                 break;
989             case ROUNDED:
990                 _rounded_type_cbmi.setSelected( true );
991                 break;
992             case RECTANGULAR:
993                 _rectangular_type_cbmi.setSelected( true );
994                 break;
995             case TRIANGULAR:
996                 _triangular_type_cbmi.setSelected( true );
997                 break;
998             case UNROOTED:
999                 _unrooted_type_cbmi.setSelected( true );
1000                 break;
1001             default:
1002                 throw new IllegalArgumentException( "unknown type: " + type );
1003         }
1004     }
1005
1006     void setTypeMenuToAllUnselected() {
1007         _convex_type_cbmi.setSelected( false );
1008         _curved_type_cbmi.setSelected( false );
1009         _euro_type_cbmi.setSelected( false );
1010         _rounded_type_cbmi.setSelected( false );
1011         _triangular_type_cbmi.setSelected( false );
1012         _rectangular_type_cbmi.setSelected( false );
1013         _unrooted_type_cbmi.setSelected( false );
1014         _circular_type_cbmi.setSelected( false );
1015     }
1016
1017     void switchColors() {
1018         final TreeColorSet colorset = _mainpanel.getTreeColorSet();
1019         final ColorSchemeChooser csc = new ColorSchemeChooser( getMainPanel(), colorset );
1020         csc.setVisible( true );
1021     }
1022
1023     void taxColor() {
1024         if ( _mainpanel.getCurrentTreePanel() != null ) {
1025             _mainpanel.getCurrentTreePanel().taxColor();
1026         }
1027     }
1028
1029     void typeChanged( final Object o ) {
1030         updateTypeCheckboxes( getOptions(), o );
1031         updateOptions( getOptions() );
1032         if ( getCurrentTreePanel() != null ) {
1033             final PHYLOGENY_GRAPHICS_TYPE previous_type = getCurrentTreePanel().getPhylogenyGraphicsType();
1034             final PHYLOGENY_GRAPHICS_TYPE new_type = getOptions().getPhylogenyGraphicsType();
1035             if ( ( ( previous_type == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) && ( new_type != PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) )
1036                     || ( ( previous_type == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) && ( new_type != PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) )
1037                     || ( ( previous_type != PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) && ( new_type == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) )
1038                     || ( ( previous_type != PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) && ( new_type == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) ) ) {
1039                 getCurrentTreePanel().getControlPanel().showWhole();
1040             }
1041             if ( getCurrentTreePanel().isPhyHasBranchLengths() && ( new_type != PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) ) {
1042                 getCurrentTreePanel().getControlPanel().setDrawPhylogramEnabled( true );
1043             }
1044             else {
1045                 getCurrentTreePanel().getControlPanel().setDrawPhylogramEnabled( false );
1046             }
1047             getCurrentTreePanel().setPhylogenyGraphicsType( getOptions().getPhylogenyGraphicsType() );
1048             updateScreenTextAntialias( getMainPanel().getTreePanels() );
1049             if ( getCurrentTreePanel().getControlPanel().getDynamicallyHideData() != null ) {
1050                 if ( new_type == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) {
1051                     getCurrentTreePanel().getControlPanel().getDynamicallyHideData().setEnabled( false );
1052                 }
1053                 else {
1054                     getCurrentTreePanel().getControlPanel().getDynamicallyHideData().setEnabled( true );
1055                 }
1056             }
1057         }
1058     }
1059
1060     void updateOptions( final Options options ) {
1061         options.setAntialiasScreen( ( _screen_antialias_cbmi != null ) && _screen_antialias_cbmi.isSelected() );
1062         options.setBackgroundColorGradient( ( _background_gradient_cbmi != null )
1063                 && _background_gradient_cbmi.isSelected() );
1064         options.setShowDomainLabels( ( _show_domain_labels != null ) && _show_domain_labels.isSelected() );
1065         options.setAbbreviateScientificTaxonNames( ( _abbreviate_scientific_names != null )
1066                 && _abbreviate_scientific_names.isSelected() );
1067         options.setColorLabelsSameAsParentBranch( ( _color_labels_same_as_parent_branch != null )
1068                 && _color_labels_same_as_parent_branch.isSelected() );
1069         options.setShowDefaultNodeShapesInternal( ( _show_default_node_shapes_internal_cbmi != null )
1070                 && _show_default_node_shapes_internal_cbmi.isSelected() );
1071         options.setShowDefaultNodeShapesExternal( ( _show_default_node_shapes_external_cbmi != null )
1072                 && _show_default_node_shapes_external_cbmi.isSelected() );
1073         options.setTaxonomyColorizeNodeShapes( ( _taxonomy_colorize_node_shapes_cbmi != null )
1074                 && _taxonomy_colorize_node_shapes_cbmi.isSelected() );
1075         if ( ( _non_lined_up_cladograms_rbmi != null ) && ( _non_lined_up_cladograms_rbmi.isSelected() ) ) {
1076             options.setCladogramType( CLADOGRAM_TYPE.NON_LINED_UP );
1077         }
1078         else if ( ( _uniform_cladograms_rbmi != null ) && ( _uniform_cladograms_rbmi.isSelected() ) ) {
1079             options.setCladogramType( CLADOGRAM_TYPE.TOTAL_NODE_SUM_DEP );
1080         }
1081         else if ( ( _ext_node_dependent_cladogram_rbmi != null ) && ( _ext_node_dependent_cladogram_rbmi.isSelected() ) ) {
1082             options.setCladogramType( CLADOGRAM_TYPE.EXT_NODE_SUM_DEP );
1083         }
1084         options.setSearchCaseSensitive( ( _search_case_senstive_cbmi != null )
1085                 && _search_case_senstive_cbmi.isSelected() );
1086         if ( ( _show_scale_cbmi != null ) && _show_scale_cbmi.isEnabled() ) {
1087             options.setShowScale( _show_scale_cbmi.isSelected() );
1088         }
1089         if ( _label_direction_cbmi != null ) {
1090             if ( _label_direction_cbmi.isSelected() ) {
1091                 options.setNodeLabelDirection( NODE_LABEL_DIRECTION.RADIAL );
1092             }
1093             else {
1094                 options.setNodeLabelDirection( NODE_LABEL_DIRECTION.HORIZONTAL );
1095             }
1096         }
1097         options.setShowOverview( ( _show_overview_cbmi != null ) && _show_overview_cbmi.isSelected() );
1098         options.setShowConfidenceStddev( ( _show_confidence_stddev_cbmi != null )
1099                 && _show_confidence_stddev_cbmi.isSelected() );
1100         if ( ( _show_branch_length_values_cbmi != null ) && _show_branch_length_values_cbmi.isEnabled() ) {
1101             options.setShowBranchLengthValues( _show_branch_length_values_cbmi.isSelected() );
1102         }
1103         options.setPrintUsingActualSize( ( _print_using_actual_size_cbmi != null )
1104                 && ( _print_using_actual_size_cbmi.isSelected() ) );
1105         options.setGraphicsExportUsingActualSize( ( _graphics_export_using_actual_size_cbmi != null )
1106                 && ( _graphics_export_using_actual_size_cbmi.isSelected() ) );
1107         options.setAntialiasPrint( ( _antialias_print_cbmi != null ) && _antialias_print_cbmi.isSelected() );
1108         if ( ( _use_brackets_for_conf_in_nh_export_cbmi != null )
1109                 && _use_brackets_for_conf_in_nh_export_cbmi.isSelected() ) {
1110             options.setNhConversionSupportValueStyle( NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS );
1111         }
1112         else if ( ( _use_internal_names_for_conf_in_nh_export_cbmi != null )
1113                 && _use_internal_names_for_conf_in_nh_export_cbmi.isSelected() ) {
1114             options.setNhConversionSupportValueStyle( NH_CONVERSION_SUPPORT_VALUE_STYLE.AS_INTERNAL_NODE_NAMES );
1115         }
1116         else {
1117             options.setNhConversionSupportValueStyle( NH_CONVERSION_SUPPORT_VALUE_STYLE.NONE );
1118         }
1119         options.setPrintBlackAndWhite( ( _print_black_and_white_cbmi != null )
1120                 && _print_black_and_white_cbmi.isSelected() );
1121         options.setInternalNumberAreConfidenceForNhParsing( ( _internal_number_are_confidence_for_nh_parsing_cbmi != null )
1122                 && _internal_number_are_confidence_for_nh_parsing_cbmi.isSelected() );
1123         if ( ( _extract_taxonomy_yes_rbmi != null ) && _extract_taxonomy_yes_rbmi.isSelected() ) {
1124             options.setTaxonomyExtractio( TAXONOMY_EXTRACTION.YES );
1125         }
1126         else if ( ( _extract_taxonomy_pfam_rbmi != null ) && _extract_taxonomy_pfam_rbmi.isSelected() ) {
1127             options.setTaxonomyExtractio( TAXONOMY_EXTRACTION.PFAM_STYLE_ONLY );
1128         }
1129         else if ( ( _extract_taxonomy_no_rbmi != null ) && _extract_taxonomy_no_rbmi.isSelected() ) {
1130             options.setTaxonomyExtractio( TAXONOMY_EXTRACTION.NO );
1131         }
1132         options.setReplaceUnderscoresInNhParsing( ( _replace_underscores_cbmi != null )
1133                 && _replace_underscores_cbmi.isSelected() );
1134         options.setMatchWholeTermsOnly( ( _search_whole_words_only_cbmi != null )
1135                 && _search_whole_words_only_cbmi.isSelected() );
1136         options.setInverseSearchResult( ( _inverse_search_result_cbmi != null )
1137                 && _inverse_search_result_cbmi.isSelected() );
1138         if ( _graphics_export_visible_only_cbmi != null ) {
1139             options.setGraphicsExportVisibleOnly( _graphics_export_visible_only_cbmi.isSelected() );
1140             if ( _graphics_export_visible_only_cbmi.isSelected() && ( _graphics_export_using_actual_size_cbmi != null ) ) {
1141                 _graphics_export_using_actual_size_cbmi.setSelected( true );
1142                 _graphics_export_using_actual_size_cbmi.setEnabled( false );
1143             }
1144             else {
1145                 _graphics_export_using_actual_size_cbmi.setEnabled( true );
1146             }
1147         }
1148         if ( ( _rectangular_type_cbmi != null ) && _rectangular_type_cbmi.isSelected() ) {
1149             options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR );
1150         }
1151         else if ( ( _triangular_type_cbmi != null ) && _triangular_type_cbmi.isSelected() ) {
1152             options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.TRIANGULAR );
1153         }
1154         else if ( ( _curved_type_cbmi != null ) && _curved_type_cbmi.isSelected() ) {
1155             options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CURVED );
1156         }
1157         else if ( ( _convex_type_cbmi != null ) && _convex_type_cbmi.isSelected() ) {
1158             options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CONVEX );
1159         }
1160         else if ( ( _euro_type_cbmi != null ) && _euro_type_cbmi.isSelected() ) {
1161             options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE );
1162         }
1163         else if ( ( _rounded_type_cbmi != null ) && _rounded_type_cbmi.isSelected() ) {
1164             options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.ROUNDED );
1165         }
1166         else if ( ( _unrooted_type_cbmi != null ) && _unrooted_type_cbmi.isSelected() ) {
1167             options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.UNROOTED );
1168         }
1169         else if ( ( _circular_type_cbmi != null ) && _circular_type_cbmi.isSelected() ) {
1170             options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CIRCULAR );
1171         }
1172     }
1173
1174     void updateTypeCheckboxes( final Options options, final Object o ) {
1175         setTypeMenuToAllUnselected();
1176         ( ( JCheckBoxMenuItem ) o ).setSelected( true );
1177     }
1178
1179     void viewAsNexus() {
1180         if ( ( _mainpanel.getCurrentPhylogeny() != null ) && !_mainpanel.getCurrentPhylogeny().isEmpty() ) {
1181             String title = "Nexus";
1182             if ( !ForesterUtil.isEmpty( _mainpanel.getCurrentPhylogeny().getName() ) ) {
1183                 title = _mainpanel.getCurrentPhylogeny().getName() + " " + title;
1184             }
1185             showTextFrame( _mainpanel.getCurrentPhylogeny().toNexus( getOptions().getNhConversionSupportValueStyle() ),
1186                            title );
1187         }
1188     }
1189
1190     void viewAsNH() {
1191         if ( ( _mainpanel.getCurrentPhylogeny() != null ) && !_mainpanel.getCurrentPhylogeny().isEmpty() ) {
1192             String title = "New Hampshire";
1193             if ( !ForesterUtil.isEmpty( _mainpanel.getCurrentPhylogeny().getName() ) ) {
1194                 title = _mainpanel.getCurrentPhylogeny().getName() + " " + title;
1195             }
1196             showTextFrame( _mainpanel.getCurrentPhylogeny()
1197                                    .toNewHampshire( false, getOptions().getNhConversionSupportValueStyle() ),
1198                            title );
1199         }
1200     }
1201
1202     void viewAsXML() {
1203         if ( ( _mainpanel.getCurrentPhylogeny() != null ) && !_mainpanel.getCurrentPhylogeny().isEmpty() ) {
1204             String title = "phyloXML";
1205             if ( !ForesterUtil.isEmpty( _mainpanel.getCurrentPhylogeny().getName() ) ) {
1206                 title = _mainpanel.getCurrentPhylogeny().getName() + " " + title;
1207             }
1208             showTextFrame( _mainpanel.getCurrentPhylogeny().toPhyloXML( 0 ), title );
1209         }
1210     }
1211
1212     private void annotateSequences() {
1213         if ( getCurrentTreePanel() != null ) {
1214             final Set<Long> nodes = getCurrentTreePanel().getFoundNodes();
1215             if ( ( nodes == null ) || nodes.isEmpty() ) {
1216                 JOptionPane
1217                         .showMessageDialog( this,
1218                                             "Need to select nodes, either via direct selection or via the \"Search\" function",
1219                                             "No nodes selected for annotation",
1220                                             JOptionPane.ERROR_MESSAGE );
1221                 return;
1222             }
1223             final Phylogeny phy = getMainPanel().getCurrentPhylogeny();
1224             if ( ( phy != null ) && !phy.isEmpty() ) {
1225                 final JTextField ref_field = new JTextField( 10 );
1226                 final JTextField desc_filed = new JTextField( 20 );
1227                 ref_field.setText( ForesterUtil.isEmpty( getPreviousNodeAnnotationReference() ) ? ""
1228                         : getPreviousNodeAnnotationReference() );
1229                 final JPanel my_panel = new JPanel();
1230                 my_panel.add( new JLabel( "Reference " ) );
1231                 my_panel.add( ref_field );
1232                 my_panel.add( Box.createHorizontalStrut( 15 ) );
1233                 my_panel.add( new JLabel( "Description " ) );
1234                 my_panel.add( desc_filed );
1235                 final int result = JOptionPane.showConfirmDialog( null,
1236                                                                   my_panel,
1237                                                                   "Enter the sequence annotation(s) for the "
1238                                                                           + nodes.size() + " selected nodes",
1239                                                                   JOptionPane.OK_CANCEL_OPTION );
1240                 if ( result == JOptionPane.OK_OPTION ) {
1241                     String ref = ref_field.getText();
1242                     String desc = desc_filed.getText();
1243                     if ( !ForesterUtil.isEmpty( ref ) ) {
1244                         ref = ref.trim();
1245                         ref = ref.replaceAll( "\\s+", " " );
1246                         if ( ( ref.indexOf( ':' ) < 1 ) || ( ref.indexOf( ':' ) > ref.length() - 2 )
1247                                 || ( ref.length() < 3 ) ) {
1248                             JOptionPane.showMessageDialog( this,
1249                                                            "Reference needs to be in the form of \"GO:1234567\"",
1250                                                            "Illegal Format for Annotation Reference",
1251                                                            JOptionPane.ERROR_MESSAGE );
1252                             return;
1253                         }
1254                     }
1255                     if ( ref != null ) {
1256                         setPreviousNodeAnnotationReference( ref );
1257                     }
1258                     if ( desc != null ) {
1259                         desc = desc.trim();
1260                         desc = desc.replaceAll( "\\s+", " " );
1261                     }
1262                     if ( !ForesterUtil.isEmpty( ref ) || !ForesterUtil.isEmpty( desc ) ) {
1263                         for( final Long id : nodes ) {
1264                             final PhylogenyNode n = phy.getNode( id );
1265                             ForesterUtil.ensurePresenceOfSequence( n );
1266                             final Annotation ann = ForesterUtil.isEmpty( ref ) ? new Annotation()
1267                                     : new Annotation( ref );
1268                             if ( !ForesterUtil.isEmpty( desc ) ) {
1269                                 ann.setDesc( desc );
1270                             }
1271                             n.getNodeData().getSequence().addAnnotation( ann );
1272                         }
1273                     }
1274                     getMainPanel().getControlPanel().showAnnotations();
1275                 }
1276             }
1277         }
1278     }
1279
1280     private void chooseFont() {
1281         final FontChooser fc = new FontChooser();
1282         fc.setFont( getMainPanel().getTreeFontSet().getLargeFont() );
1283         fc.showDialog( this, "Select the Base Font" );
1284         getMainPanel().getTreeFontSet().setBaseFont( fc.getFont() );
1285     }
1286
1287     private void chooseMinimalConfidence() {
1288         final String s = ( String ) JOptionPane
1289                 .showInputDialog( this,
1290                                   "Please enter the minimum for confidence values to be displayed.\n"
1291                                           + "[current value: " + getOptions().getMinConfidenceValue() + "]\n",
1292                                   "Minimal Confidence Value",
1293                                   JOptionPane.QUESTION_MESSAGE,
1294                                   null,
1295                                   null,
1296                                   getOptions().getMinConfidenceValue() );
1297         if ( !ForesterUtil.isEmpty( s ) ) {
1298             boolean success = true;
1299             double m = 0.0;
1300             final String m_str = s.trim();
1301             if ( !ForesterUtil.isEmpty( m_str ) ) {
1302                 try {
1303                     m = Double.parseDouble( m_str );
1304                 }
1305                 catch ( final Exception ex ) {
1306                     success = false;
1307                 }
1308             }
1309             else {
1310                 success = false;
1311             }
1312             if ( success && ( m >= 0.0 ) ) {
1313                 getOptions().setMinConfidenceValue( m );
1314             }
1315         }
1316     }
1317
1318     private void doUpdateProcessMenu() {
1319         if ( _process_pool.size() > 0 ) {
1320             if ( _process_menu == null ) {
1321                 _process_menu = createMenu( "", getConfiguration() );
1322                 _process_menu.setForeground( Color.RED );
1323             }
1324             _process_menu.removeAll();
1325             final String text = "processes running: " + _process_pool.size();
1326             _process_menu.setText( text );
1327             _jmenubar.add( _process_menu );
1328             for( int i = 0; i < _process_pool.size(); ++i ) {
1329                 final ProcessRunning p = _process_pool.getProcessByIndex( i );
1330                 _process_menu.add( customizeJMenuItem( new JMenuItem( p.getName() + " [" + p.getStart() + "]" ) ) );
1331             }
1332         }
1333         else {
1334             if ( _process_menu != null ) {
1335                 _process_menu.removeAll();
1336                 _jmenubar.remove( _process_menu );
1337             }
1338         }
1339         _jmenubar.validate();
1340         _jmenubar.repaint();
1341         repaint();
1342     }
1343
1344     private String getPreviousNodeAnnotationReference() {
1345         return _previous_node_annotation_ref;
1346     }
1347
1348     private void removeBranchColors() {
1349         if ( getMainPanel().getCurrentPhylogeny() != null ) {
1350             AptxUtil.removeBranchColors( getMainPanel().getCurrentPhylogeny() );
1351         }
1352     }
1353
1354     private void setPreviousNodeAnnotationReference( final String previous_node_annotation_ref ) {
1355         _previous_node_annotation_ref = previous_node_annotation_ref;
1356     }
1357
1358     /**
1359      * Display the about box.
1360      */
1361     static void about() {
1362         final StringBuffer about = new StringBuffer( "Archaeopteryx\nVersion " + Constants.VERSION + "\n" );
1363         about.append( "Copyright (C) 2013 Christian M. Zmasek\n" );
1364         about.append( "All Rights Reserved\n" );
1365         about.append( "License: GNU Lesser General Public License (LGPL)\n" );
1366         about.append( "Last modified: " + Constants.PRG_DATE + "\n" );
1367         about.append( "Based on: " + ForesterUtil.getForesterLibraryInformation() + "\n" );
1368         about.append( "phyloXML version : " + ForesterConstants.PHYLO_XML_VERSION + "\n" );
1369         about.append( "phyloXML location: " + ForesterConstants.PHYLO_XML_LOCATION + "\n" );
1370         if ( !ForesterUtil.isEmpty( ForesterUtil.JAVA_VERSION ) && !ForesterUtil.isEmpty( ForesterUtil.JAVA_VENDOR ) ) {
1371             about.append( "[your Java version: " + ForesterUtil.JAVA_VERSION + " " + ForesterUtil.JAVA_VENDOR + "]\n" );
1372         }
1373         if ( !ForesterUtil.isEmpty( ForesterUtil.OS_NAME ) && !ForesterUtil.isEmpty( ForesterUtil.OS_ARCH )
1374                 && !ForesterUtil.isEmpty( ForesterUtil.OS_VERSION ) ) {
1375             about.append( "[your OS: " + ForesterUtil.OS_NAME + " " + ForesterUtil.OS_ARCH + " "
1376                     + ForesterUtil.OS_VERSION + "]\n" );
1377         }
1378         final Runtime rt = java.lang.Runtime.getRuntime();
1379         final long free_memory = rt.freeMemory() / 1000000;
1380         final long total_memory = rt.totalMemory() / 1000000;
1381         about.append( "[free memory: " + free_memory + "MB, total memory: " + total_memory + "MB]\n" );
1382         about.append( "[locale: " + Locale.getDefault() + "]\n" );
1383         about.append( "References:\n" );
1384         about.append( Constants.PHYLOXML_REFERENCE_SHORT + "\n" );
1385         about.append( "For more information & download:\n" );
1386         about.append( Constants.APTX_WEB_SITE + "\n" );
1387         about.append( "Comments: " + Constants.AUTHOR_EMAIL );
1388         JOptionPane.showMessageDialog( null, about, Constants.PRG_NAME, JOptionPane.PLAIN_MESSAGE );
1389     }
1390
1391     static void chooseNodeSize( final Options options, final Component parent ) {
1392         final String s = ( String ) JOptionPane.showInputDialog( parent,
1393                                                                  "Please enter the default size for node shapes.\n"
1394                                                                          + "[current value: "
1395                                                                          + options.getDefaultNodeShapeSize() + "]\n",
1396                                                                  "Node Shape Size",
1397                                                                  JOptionPane.QUESTION_MESSAGE,
1398                                                                  null,
1399                                                                  null,
1400                                                                  options.getDefaultNodeShapeSize() );
1401         if ( !ForesterUtil.isEmpty( s ) ) {
1402             boolean success = true;
1403             double m = 0.0;
1404             final String m_str = s.trim();
1405             if ( !ForesterUtil.isEmpty( m_str ) ) {
1406                 try {
1407                     m = Double.parseDouble( m_str );
1408                 }
1409                 catch ( final Exception ex ) {
1410                     success = false;
1411                 }
1412             }
1413             else {
1414                 success = false;
1415             }
1416             if ( success && ( m >= 0.0 ) ) {
1417                 final short size = ForesterUtil.roundToShort( m );
1418                 if ( size >= 0.0 ) {
1419                     options.setDefaultNodeShapeSize( size );
1420                 }
1421             }
1422         }
1423     }
1424
1425     static String createCurrentFontDesc( final TreeFontSet tree_font_set ) {
1426         return tree_font_set.getLargeFont().getFamily() + " " + tree_font_set.getLargeFont().getSize();
1427     }
1428
1429     static JMenu createMenu( final String title, final Configuration conf ) {
1430         final JMenu jmenu = new JMenu( title );
1431         if ( !conf.isUseNativeUI() ) {
1432             jmenu.setFont( MainFrame.menu_font );
1433             jmenu.setBackground( conf.getGuiMenuBackgroundColor() );
1434             jmenu.setForeground( conf.getGuiMenuTextColor() );
1435         }
1436         return jmenu;
1437     }
1438
1439     static JMenuItem customizeMenuItemAsLabel( final JMenuItem label, final Configuration configuration ) {
1440         label.setFont( MainFrame.menu_font.deriveFont( Font.BOLD ) );
1441         if ( !configuration.isUseNativeUI() ) {
1442             label.setBackground( configuration.getGuiMenuBackgroundColor() );
1443             label.setForeground( configuration.getGuiMenuTextColor() );
1444             label.setOpaque( true );
1445         }
1446         label.setSelected( false );
1447         label.setEnabled( false );
1448         return label;
1449     }
1450
1451     static void cycleNodeFill( final Options op, final TreePanel tree_panel ) {
1452         switch ( op.getDefaultNodeFill() ) {
1453             case GRADIENT:
1454                 op.setDefaultNodeFill( NodeFill.SOLID );
1455                 break;
1456             case NONE:
1457                 op.setDefaultNodeFill( NodeFill.GRADIENT );
1458                 break;
1459             case SOLID:
1460                 op.setDefaultNodeFill( NodeFill.NONE );
1461                 break;
1462             default:
1463                 throw new RuntimeException( "unknown fill: " + op.getDefaultNodeFill() );
1464         }
1465     }
1466
1467     static void cycleNodeShape( final Options op, final TreePanel tree_panel ) {
1468         switch ( op.getDefaultNodeShape() ) {
1469             case CIRCLE:
1470                 op.setDefaultNodeShape( NodeShape.RECTANGLE );
1471                 break;
1472             case RECTANGLE:
1473                 op.setDefaultNodeShape( NodeShape.CIRCLE );
1474                 break;
1475             default:
1476                 throw new RuntimeException( "unknown shape: " + op.getDefaultNodeShape() );
1477         }
1478     }
1479
1480     static void cycleOverview( final Options op, final TreePanel tree_panel ) {
1481         switch ( op.getOvPlacement() ) {
1482             case LOWER_LEFT:
1483                 op.setOvPlacement( Options.OVERVIEW_PLACEMENT_TYPE.UPPER_LEFT );
1484                 break;
1485             case LOWER_RIGHT:
1486                 op.setOvPlacement( Options.OVERVIEW_PLACEMENT_TYPE.LOWER_LEFT );
1487                 break;
1488             case UPPER_LEFT:
1489                 op.setOvPlacement( Options.OVERVIEW_PLACEMENT_TYPE.UPPER_RIGHT );
1490                 break;
1491             case UPPER_RIGHT:
1492                 op.setOvPlacement( Options.OVERVIEW_PLACEMENT_TYPE.LOWER_RIGHT );
1493                 break;
1494             default:
1495                 throw new RuntimeException( "unknown placement: " + op.getOvPlacement() );
1496         }
1497         if ( tree_panel != null ) {
1498             tree_panel.updateOvSettings();
1499         }
1500     }
1501
1502     static void setCycleNodeFillMenuItem( final JMenuItem mi, final Options options ) {
1503         if ( ( options != null ) && ( options.getDefaultNodeFill() != null ) ) {
1504             mi.setText( "Cycle Node Shape Fill Type... (current: "
1505                     + options.getDefaultNodeFill().toString().toLowerCase() + ")" );
1506         }
1507         else {
1508             mi.setText( "Cycle Node Shape Fill Type..." );
1509         }
1510     }
1511
1512     static void setCycleNodeShapeMenuItem( final JMenuItem mi, final Options options ) {
1513         if ( ( options != null ) && ( options.getDefaultNodeShape() != null ) ) {
1514             mi.setText( "Cycle Node Shape Fill Type... (current: "
1515                     + options.getDefaultNodeShape().toString().toLowerCase() + ")" );
1516         }
1517         else {
1518             mi.setText( "Cycle Node Shape Fill Type..." );
1519         }
1520     }
1521
1522     static void setOvPlacementColorChooseMenuItem( final JMenuItem mi, final Options options ) {
1523         if ( ( options != null ) && ( options.getOvPlacement() != null ) ) {
1524             mi.setText( "Cycle Overview Placement... (current: " + options.getOvPlacement() + ")" );
1525         }
1526         else {
1527             mi.setText( "Cycle Overview Placement..." );
1528         }
1529     }
1530
1531     static void setTextColorChooseMenuItem( final JMenuItem mi, final TreePanel tree_panel ) {
1532         if ( ( tree_panel != null ) && ( tree_panel.getTreeColorSet() != null ) ) {
1533             mi.setText( "Select Colors... (current: " + tree_panel.getTreeColorSet().getCurrentColorSchemeName() + ")" );
1534         }
1535         else {
1536             mi.setText( "Select Colors..." );
1537         }
1538     }
1539
1540     static void setTextForFontChooserMenuItem( final JMenuItem mi, final String font_desc ) {
1541         mi.setText( "Select Font... (current: " + font_desc + ")" );
1542     }
1543
1544     static void setTextMinSupportMenuItem( final JMenuItem mi, final Options options, final TreePanel current_tree_panel ) {
1545         if ( ( current_tree_panel == null ) || ( current_tree_panel.getPhylogeny() == null ) ) {
1546             mi.setEnabled( true );
1547         }
1548         else if ( AptxUtil.isHasAtLeastOneBranchWithSupportValues( current_tree_panel.getPhylogeny() ) ) {
1549             mi.setEnabled( true );
1550         }
1551         else {
1552             mi.setEnabled( false );
1553         }
1554         mi.setText( "Enter Min Confidence Value... (current: " + options.getMinConfidenceValue() + ")" );
1555     }
1556
1557     static void setTextNodeSizeMenuItem( final JMenuItem mi, final Options options ) {
1558         mi.setText( "Enter Default Node Shape Size... (current: " + options.getDefaultNodeShapeSize() + ")" );
1559     }
1560
1561     static void updateOptionsMenuDependingOnPhylogenyType( final MainPanel main_panel,
1562                                                            final JCheckBoxMenuItem scale,
1563                                                            final JCheckBoxMenuItem branch_lengths,
1564                                                            final JRadioButtonMenuItem non_lined_up,
1565                                                            final JRadioButtonMenuItem uniform_clado,
1566                                                            final JRadioButtonMenuItem nonuniform_clado,
1567                                                            final JCheckBoxMenuItem label_direction_cbmi ) {
1568         final TreePanel tree_panel = main_panel.getCurrentTreePanel();
1569         final ControlPanel control = main_panel.getControlPanel();
1570         final Options options = main_panel.getOptions();
1571         scale.setSelected( options.isShowScale() );
1572         branch_lengths.setSelected( options.isShowBranchLengthValues() );
1573         // non_lined_up.setSelected( options.isNonLinedUpCladogram() );
1574         if ( ( tree_panel != null ) && ( !tree_panel.isPhyHasBranchLengths() ) ) {
1575             scale.setSelected( false );
1576             scale.setEnabled( false );
1577             branch_lengths.setSelected( false );
1578             branch_lengths.setEnabled( false );
1579         }
1580         else if ( ( tree_panel != null ) && !control.isDrawPhylogram() ) {
1581             scale.setSelected( false );
1582             scale.setEnabled( false );
1583             branch_lengths.setEnabled( true );
1584         }
1585         else {
1586             scale.setEnabled( true );
1587             branch_lengths.setEnabled( true );
1588         }
1589         if ( ( tree_panel != null )
1590                 && ( ( tree_panel.getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.ROUNDED )
1591                         && ( tree_panel.getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE ) && ( tree_panel
1592                         .getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR ) ) ) {
1593             branch_lengths.setSelected( false );
1594             branch_lengths.setEnabled( false );
1595         }
1596         if ( tree_panel != null ) {
1597             if ( ( tree_panel.getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR )
1598                     || ( tree_panel.getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) ) {
1599                 non_lined_up.setEnabled( false );
1600                 uniform_clado.setEnabled( false );
1601                 nonuniform_clado.setEnabled( false );
1602             }
1603             else {
1604                 non_lined_up.setEnabled( true );
1605                 uniform_clado.setEnabled( true );
1606                 nonuniform_clado.setEnabled( true );
1607             }
1608         }
1609         else {
1610             if ( ( tree_panel != null )
1611                     && ( ( tree_panel.getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE ) && ( tree_panel
1612                             .getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR ) ) ) {
1613                 branch_lengths.setSelected( false );
1614                 branch_lengths.setEnabled( false );
1615             }
1616             if ( ( tree_panel != null )
1617                     && ( ( tree_panel.getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) || ( tree_panel
1618                             .getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) ) ) {
1619                 non_lined_up.setEnabled( false );
1620             }
1621             else {
1622                 // non_lined_up.setSelected( options.isNonLinedUpCladogram() );
1623                 non_lined_up.setEnabled( true );
1624             }
1625         }
1626         label_direction_cbmi.setEnabled( true );
1627         if ( tree_panel != null ) {
1628             if ( ( tree_panel.getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.UNROOTED )
1629                     && ( tree_panel.getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) ) {
1630                 label_direction_cbmi.setEnabled( false );
1631             }
1632             if ( tree_panel.getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) {
1633                 scale.setSelected( false );
1634                 scale.setEnabled( false );
1635             }
1636         }
1637     }
1638
1639     static void updateScreenTextAntialias( final List<TreePanel> treepanels ) {
1640         for( final TreePanel tree_panel : treepanels ) {
1641             tree_panel.setTextAntialias();
1642         }
1643     }
1644 }