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