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