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