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