annotation things
[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.PhylogenyNodeI.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                   _infer_common_sn_names_item;
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_uniprot_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     JCheckBoxMenuItem           _extract_pfam_style_tax_codes_cbmi;
190     JCheckBoxMenuItem           _replace_underscores_cbmi;
191     JCheckBoxMenuItem           _use_brackets_for_conf_in_nh_export_cbmi;
192     JCheckBoxMenuItem           _use_internal_names_for_conf_in_nh_export_cbmi;
193     // _  search
194     JCheckBoxMenuItem           _search_case_senstive_cbmi;
195     JCheckBoxMenuItem           _search_whole_words_only_cbmi;
196     JCheckBoxMenuItem           _inverse_search_result_cbmi;
197     // type menu:
198     JMenu                       _type_menu;
199     JCheckBoxMenuItem           _rectangular_type_cbmi;
200     JCheckBoxMenuItem           _triangular_type_cbmi;
201     JCheckBoxMenuItem           _curved_type_cbmi;
202     JCheckBoxMenuItem           _convex_type_cbmi;
203     JCheckBoxMenuItem           _euro_type_cbmi;
204     JCheckBoxMenuItem           _rounded_type_cbmi;
205     JCheckBoxMenuItem           _unrooted_type_cbmi;
206     JCheckBoxMenuItem           _circular_type_cbmi;
207     // view as text menu:
208     JMenuItem                   _view_as_NH_item;
209     JMenuItem                   _view_as_NHX_item;
210     JMenuItem                   _view_as_XML_item;
211     JMenuItem                   _view_as_nexus_item;
212     JMenuItem                   _display_basic_information_item;
213     // help menu:
214     JMenuItem                   _about_item;
215     JMenuItem                   _help_item;
216     JMenuItem                   _website_item;
217     JMenuItem                   _phyloxml_website_item;
218     JMenuItem                   _phyloxml_ref_item;
219     JMenuItem                   _aptx_ref_item;
220     // process menu:
221     JMenu                       _process_menu;
222     // Handy pointers to child components:
223     MainPanel                   _mainpanel;
224     Container                   _contentpane;
225     final LinkedList<TextFrame> _textframes                             = new LinkedList<TextFrame>();                                                                                                                                         ;
226     Configuration               _configuration;
227     JMenuItem                   _remove_branch_color_item;
228     Options                     _options;
229     InferenceManager            _inference_manager;
230     final ProcessPool           _process_pool;
231     private String              _previous_node_annotation_ref;
232
233     MainFrame() {
234         _process_pool = ProcessPool.createInstance();
235     }
236
237     /**
238      * Action performed.
239      */
240     @Override
241     public void actionPerformed( final ActionEvent e ) {
242         final Object o = e.getSource();
243         boolean is_applet = false;
244         JApplet applet = null;
245         if ( getCurrentTreePanel() != null ) {
246             is_applet = getCurrentTreePanel().isApplet();
247             if ( is_applet ) {
248                 applet = getCurrentTreePanel().obtainApplet();
249             }
250         }
251         if ( o == _open_url_item ) {
252             readPhylogeniesFromURL();
253         }
254         else if ( o == _exit_item ) {
255             close();
256         }
257         else if ( o == _taxcolor_item ) {
258             taxColor();
259         }
260         else if ( o == _confcolor_item ) {
261             confColor();
262         }
263         else if ( o == _color_rank_jmi ) {
264             colorRank();
265         }
266         else if ( o == _infer_common_sn_names_item ) {
267             if ( isSubtreeDisplayed() ) {
268                 return;
269             }
270             if ( getCurrentTreePanel() != null ) {
271                 getCurrentTreePanel().inferCommonPartOfScientificNames();
272             }
273         }
274         else if ( o == _collapse_species_specific_subtrees ) {
275             if ( isSubtreeDisplayed() ) {
276                 return;
277             }
278             if ( getCurrentTreePanel() != null ) {
279                 getCurrentTreePanel().collapseSpeciesSpecificSubtrees();
280             }
281         }
282         else if ( o == _remove_branch_color_item ) {
283             if ( isSubtreeDisplayed() ) {
284                 return;
285             }
286             removeBranchColors();
287         }
288         else if ( o == _midpoint_root_item ) {
289             if ( isSubtreeDisplayed() ) {
290                 return;
291             }
292             midpointRoot();
293         }
294         else if ( o == _annotate_item ) {
295             annotateSequences();
296         }
297         else if ( o == _switch_colors_mi ) {
298             switchColors();
299         }
300         else if ( o == _display_basic_information_item ) {
301             displayBasicInformation();
302         }
303         else if ( o == _view_as_NH_item ) {
304             viewAsNH();
305         }
306         else if ( o == _view_as_NHX_item ) {
307             viewAsNHX();
308         }
309         else if ( o == _view_as_XML_item ) {
310             viewAsXML();
311         }
312         else if ( o == _view_as_nexus_item ) {
313             viewAsNexus();
314         }
315         else if ( o == _super_tiny_fonts_item ) {
316             if ( getCurrentTreePanel() != null ) {
317                 getCurrentTreePanel().setSuperTinyFonts();
318                 getCurrentTreePanel().repaint();
319             }
320         }
321         else if ( o == _tiny_fonts_item ) {
322             if ( getCurrentTreePanel() != null ) {
323                 getCurrentTreePanel().setTinyFonts();
324                 getCurrentTreePanel().repaint();
325             }
326         }
327         else if ( o == _small_fonts_item ) {
328             if ( getCurrentTreePanel() != null ) {
329                 getCurrentTreePanel().setSmallFonts();
330                 getCurrentTreePanel().repaint();
331             }
332         }
333         else if ( o == _medium_fonts_item ) {
334             if ( getCurrentTreePanel() != null ) {
335                 getCurrentTreePanel().setMediumFonts();
336                 getCurrentTreePanel().repaint();
337             }
338         }
339         else if ( o == _large_fonts_item ) {
340             if ( getCurrentTreePanel() != null ) {
341                 getCurrentTreePanel().setLargeFonts();
342                 getCurrentTreePanel().repaint();
343             }
344         }
345         else if ( o == _choose_font_mi ) {
346             chooseFont();
347         }
348         else if ( o == _choose_minimal_confidence_mi ) {
349             chooseMinimalConfidence();
350         }
351         else if ( o == _choose_node_size_mi ) {
352             chooseNodeSize( getOptions(), this );
353         }
354         else if ( o == _overview_placment_mi ) {
355             MainFrame.cycleOverview( getOptions(), getCurrentTreePanel() );
356         }
357         else if ( o == _cycle_node_fill_mi ) {
358             MainFrame.cycleNodeFill( getOptions(), getCurrentTreePanel() );
359         }
360         else if ( o == _cycle_node_shape_mi ) {
361             MainFrame.cycleNodeShape( getOptions(), getCurrentTreePanel() );
362         }
363         else if ( o == _screen_antialias_cbmi ) {
364             updateOptions( getOptions() );
365             updateScreenTextAntialias( getMainPanel().getTreePanels() );
366         }
367         else if ( o == _background_gradient_cbmi ) {
368             updateOptions( getOptions() );
369         }
370         else if ( o == _show_domain_labels ) {
371             updateOptions( getOptions() );
372         }
373         else if ( o == _abbreviate_scientific_names ) {
374             updateOptions( getOptions() );
375         }
376         else if ( o == _color_labels_same_as_parent_branch ) {
377             updateOptions( getOptions() );
378         }
379         else if ( o == _show_default_node_shapes_cbmi ) {
380             updateOptions( getOptions() );
381         }
382         else if ( o == _taxonomy_colorize_node_shapes_cbmi ) {
383             updateOptions( getOptions() );
384         }
385         else if ( o == _non_lined_up_cladograms_rbmi ) {
386             updateOptions( getOptions() );
387             showWhole();
388         }
389         else if ( o == _uniform_cladograms_rbmi ) {
390             updateOptions( getOptions() );
391             showWhole();
392         }
393         else if ( o == _ext_node_dependent_cladogram_rbmi ) {
394             updateOptions( getOptions() );
395             showWhole();
396         }
397         else if ( o == _search_case_senstive_cbmi ) {
398             updateOptions( getOptions() );
399             getMainPanel().getControlPanel().search();
400         }
401         else if ( o == _search_whole_words_only_cbmi ) {
402             updateOptions( getOptions() );
403             getMainPanel().getControlPanel().search();
404         }
405         else if ( o == _inverse_search_result_cbmi ) {
406             updateOptions( getOptions() );
407             getMainPanel().getControlPanel().search();
408         }
409         else if ( o == _show_scale_cbmi ) {
410             updateOptions( getOptions() );
411         }
412         else if ( o == _show_branch_length_values_cbmi ) {
413             updateOptions( getOptions() );
414         }
415         else if ( o == _show_confidence_stddev_cbmi ) {
416             updateOptions( getOptions() );
417         }
418         else if ( o == _use_brackets_for_conf_in_nh_export_cbmi ) {
419             if ( _use_brackets_for_conf_in_nh_export_cbmi.isSelected() ) {
420                 _use_internal_names_for_conf_in_nh_export_cbmi.setSelected( false );
421             }
422             updateOptions( getOptions() );
423         }
424         else if ( o == _use_internal_names_for_conf_in_nh_export_cbmi ) {
425             if ( _use_internal_names_for_conf_in_nh_export_cbmi.isSelected() ) {
426                 _use_brackets_for_conf_in_nh_export_cbmi.setSelected( false );
427             }
428             updateOptions( getOptions() );
429         }
430         else if ( o == _label_direction_cbmi ) {
431             updateOptions( getOptions() );
432         }
433         else if ( o == _show_overview_cbmi ) {
434             updateOptions( getOptions() );
435             if ( getCurrentTreePanel() != null ) {
436                 getCurrentTreePanel().updateOvSizes();
437             }
438         }
439         else if ( ( o == _rectangular_type_cbmi ) || ( o == _triangular_type_cbmi ) || ( o == _curved_type_cbmi )
440                 || ( o == _convex_type_cbmi ) || ( o == _euro_type_cbmi ) || ( o == _rounded_type_cbmi )
441                 || ( o == _unrooted_type_cbmi ) || ( o == _circular_type_cbmi ) ) {
442             typeChanged( o );
443         }
444         else if ( o == _about_item ) {
445             about();
446         }
447         else if ( o == _help_item ) {
448             help( getConfiguration().getWebLinks() );
449         }
450         else if ( o == _website_item ) {
451             try {
452                 AptxUtil.openWebsite( Constants.APTX_WEB_SITE, is_applet, applet );
453             }
454             catch ( final IOException e1 ) {
455                 ForesterUtil.printErrorMessage( Constants.PRG_NAME, e1.toString() );
456             }
457         }
458         else if ( o == _phyloxml_website_item ) {
459             try {
460                 AptxUtil.openWebsite( Constants.PHYLOXML_WEB_SITE, is_applet, applet );
461             }
462             catch ( final IOException e1 ) {
463                 ForesterUtil.printErrorMessage( Constants.PRG_NAME, e1.toString() );
464             }
465         }
466         else if ( o == _aptx_ref_item ) {
467             try {
468                 AptxUtil.openWebsite( Constants.APTX_REFERENCE_URL, is_applet, applet );
469             }
470             catch ( final IOException e1 ) {
471                 ForesterUtil.printErrorMessage( Constants.PRG_NAME, e1.toString() );
472             }
473         }
474         else if ( o == _phyloxml_ref_item ) {
475             try {
476                 AptxUtil.openWebsite( Constants.PHYLOXML_REFERENCE_URL, is_applet, applet );
477             }
478             catch ( final IOException e1 ) {
479                 ForesterUtil.printErrorMessage( Constants.PRG_NAME, e1.toString() );
480             }
481         }
482         else {
483             if ( _load_phylogeny_from_webservice_menu_items != null ) {
484                 for( int i = 0; i < _load_phylogeny_from_webservice_menu_items.length; ++i ) {
485                     if ( o == _load_phylogeny_from_webservice_menu_items[ i ] ) {
486                         readPhylogeniesFromWebservice( i );
487                     }
488                 }
489             }
490         }
491         _contentpane.repaint();
492     }
493
494     public Configuration getConfiguration() {
495         return _configuration;
496     }
497
498     public InferenceManager getInferenceManager() {
499         return _inference_manager;
500     }
501
502     public MainPanel getMainPanel() {
503         return _mainpanel;
504     }
505
506     public Options getOptions() {
507         return _options;
508     }
509
510     public ProcessPool getProcessPool() {
511         return _process_pool;
512     }
513
514     public void showTextFrame( final String s, final String title ) {
515         checkTextFrames();
516         _textframes.addLast( TextFrame.instantiate( s, title, _textframes ) );
517     }
518
519     public void showWhole() {
520         _mainpanel.getControlPanel().showWhole();
521     }
522
523     public void updateProcessMenu() {
524         // In general Swing is not thread safe.
525         // See "Swing's Threading Policy".
526         SwingUtilities.invokeLater( new Runnable() {
527
528             @Override
529             public void run() {
530                 doUpdateProcessMenu();
531             }
532         } );
533     }
534
535     void activateSaveAllIfNeeded() {
536         if ( ( getMainPanel().getTabbedPane() != null ) && ( getMainPanel().getTabbedPane().getTabCount() > 1 ) ) {
537             _save_all_item.setEnabled( true );
538         }
539         else {
540             _save_all_item.setEnabled( false );
541         }
542     }
543
544     void buildFileMenu() {
545         _file_jmenu = createMenu( "File", getConfiguration() );
546         _file_jmenu.add( _open_url_item = new JMenuItem( "Read tree from URL/webservice..." ) );
547         _file_jmenu.addSeparator();
548         _file_jmenu.add( _exit_item = new JMenuItem( "Exit" ) );
549         customizeJMenuItem( _open_url_item );
550         customizeJMenuItem( _exit_item );
551         _jmenubar.add( _file_jmenu );
552     }
553
554     void buildFontSizeMenu() {
555         _font_size_menu = createMenu( FONT_SIZE_MENU_LABEL, getConfiguration() );
556         _font_size_menu.add( _super_tiny_fonts_item = new JMenuItem( "Super Tiny Fonts" ) );
557         _font_size_menu.add( _tiny_fonts_item = new JMenuItem( "Tiny Fonts" ) );
558         _font_size_menu.add( _small_fonts_item = new JMenuItem( "Small Fonts" ) );
559         _font_size_menu.add( _medium_fonts_item = new JMenuItem( "Medium Fonts" ) );
560         _font_size_menu.add( _large_fonts_item = new JMenuItem( "Large Fonts" ) );
561         customizeJMenuItem( _super_tiny_fonts_item );
562         customizeJMenuItem( _tiny_fonts_item );
563         customizeJMenuItem( _small_fonts_item );
564         customizeJMenuItem( _medium_fonts_item );
565         customizeJMenuItem( _large_fonts_item );
566         _jmenubar.add( _font_size_menu );
567     }
568
569     void buildHelpMenu() {
570         _help_jmenu = createMenu( "Help", getConfiguration() );
571         _help_jmenu.add( _help_item = new JMenuItem( "Help" ) );
572         _help_jmenu.add( _website_item = new JMenuItem( "Archaeopteryx Home" ) );
573         _aptx_ref_item = new JMenuItem( "Archaeopteryx Reference" );
574         _help_jmenu.add( _phyloxml_website_item = new JMenuItem( "phyloXML Home" ) );
575         _help_jmenu.add( _phyloxml_ref_item = new JMenuItem( "phyloXML Reference" ) );
576         _help_jmenu.addSeparator();
577         _help_jmenu.add( _about_item = new JMenuItem( "About" ) );
578         customizeJMenuItem( _help_item );
579         customizeJMenuItem( _website_item );
580         customizeJMenuItem( _phyloxml_website_item );
581         customizeJMenuItem( _aptx_ref_item );
582         customizeJMenuItem( _phyloxml_ref_item );
583         customizeJMenuItem( _about_item );
584         _phyloxml_ref_item.setToolTipText( PHYLOXML_REF_TOOL_TIP );
585         _aptx_ref_item.setToolTipText( APTX_REF_TOOL_TIP );
586         _jmenubar.add( _help_jmenu );
587     }
588
589     void buildTypeMenu() {
590         _type_menu = createMenu( TYPE_MENU_HEADER, getConfiguration() );
591         _type_menu.add( _rectangular_type_cbmi = new JCheckBoxMenuItem( MainFrame.RECTANGULAR_TYPE_CBMI_LABEL ) );
592         _type_menu.add( _euro_type_cbmi = new JCheckBoxMenuItem( MainFrame.EURO_TYPE_CBMI_LABEL ) );
593         _type_menu.add( _rounded_type_cbmi = new JCheckBoxMenuItem( MainFrame.ROUNDED_TYPE_CBMI_LABEL ) );
594         _type_menu.add( _curved_type_cbmi = new JCheckBoxMenuItem( MainFrame.CURVED_TYPE_CBMI_LABEL ) );
595         _type_menu.add( _triangular_type_cbmi = new JCheckBoxMenuItem( MainFrame.TRIANGULAR_TYPE_CBMI_LABEL ) );
596         _type_menu.add( _convex_type_cbmi = new JCheckBoxMenuItem( MainFrame.CONVEX_TYPE_CBMI_LABEL ) );
597         _type_menu.add( _unrooted_type_cbmi = new JCheckBoxMenuItem( MainFrame.UNROOTED_TYPE_CBMI_LABEL ) );
598         _type_menu.add( _circular_type_cbmi = new JCheckBoxMenuItem( MainFrame.CIRCULAR_TYPE_CBMI_LABEL ) );
599         customizeCheckBoxMenuItem( _rectangular_type_cbmi, false );
600         customizeCheckBoxMenuItem( _triangular_type_cbmi, false );
601         customizeCheckBoxMenuItem( _euro_type_cbmi, false );
602         customizeCheckBoxMenuItem( _rounded_type_cbmi, false );
603         customizeCheckBoxMenuItem( _curved_type_cbmi, false );
604         customizeCheckBoxMenuItem( _convex_type_cbmi, false );
605         customizeCheckBoxMenuItem( _unrooted_type_cbmi, false );
606         customizeCheckBoxMenuItem( _circular_type_cbmi, false );
607         _unrooted_type_cbmi.setToolTipText( MainFrame.USE_MOUSEWHEEL_SHIFT_TO_ROTATE );
608         _circular_type_cbmi.setToolTipText( MainFrame.USE_MOUSEWHEEL_SHIFT_TO_ROTATE );
609         initializeTypeMenu( getOptions() );
610         _jmenubar.add( _type_menu );
611     }
612
613     void buildViewMenu() {
614         _view_jmenu = createMenu( "View", getConfiguration() );
615         _view_jmenu.add( _display_basic_information_item = new JMenuItem( "Display Basic Information" ) );
616         _view_jmenu.addSeparator();
617         _view_jmenu.add( _view_as_XML_item = new JMenuItem( "View as phyloXML" ) );
618         _view_jmenu.add( _view_as_NH_item = new JMenuItem( "View as Newick" ) );
619         _view_jmenu.add( _view_as_NHX_item = new JMenuItem( "View as NHX" ) );
620         _view_jmenu.add( _view_as_nexus_item = new JMenuItem( "View as Nexus" ) );
621         customizeJMenuItem( _display_basic_information_item );
622         customizeJMenuItem( _view_as_NH_item );
623         customizeJMenuItem( _view_as_NHX_item );
624         customizeJMenuItem( _view_as_XML_item );
625         customizeJMenuItem( _view_as_nexus_item );
626         _jmenubar.add( _view_jmenu );
627     }
628
629     void checkTextFrames() {
630         if ( _textframes.size() > 5 ) {
631             try {
632                 if ( _textframes.getFirst() != null ) {
633                     _textframes.getFirst().removeMe();
634                 }
635                 else {
636                     _textframes.removeFirst();
637                 }
638             }
639             catch ( final NoSuchElementException e ) {
640                 // Ignore.
641             }
642         }
643     }
644
645     void close() {
646         removeAllTextFrames();
647         if ( _mainpanel != null ) {
648             _mainpanel.terminate();
649         }
650         if ( _contentpane != null ) {
651             _contentpane.removeAll();
652         }
653         setVisible( false );
654         dispose();
655     }
656
657     void colorRank() {
658         if ( _mainpanel.getCurrentTreePanel() != null ) {
659             final String[] ranks = AptxUtil.getAllPossibleRanks();
660             final String rank = ( String ) JOptionPane
661                     .showInputDialog( this,
662                                       "What rank should the colorization be based on",
663                                       "Rank Selection",
664                                       JOptionPane.QUESTION_MESSAGE,
665                                       null,
666                                       ranks,
667                                       null );
668             if ( !ForesterUtil.isEmpty( rank ) ) {
669                 _mainpanel.getCurrentTreePanel().colorRank( rank );
670             }
671         }
672     }
673
674     void confColor() {
675         if ( _mainpanel.getCurrentTreePanel() != null ) {
676             _mainpanel.getCurrentTreePanel().confColor();
677         }
678     }
679
680     void customizeCheckBoxMenuItem( final JCheckBoxMenuItem item, final boolean is_selected ) {
681         if ( item != null ) {
682             item.setFont( MainFrame.menu_font );
683             if ( !getConfiguration().isUseNativeUI() ) {
684                 item.setBackground( getConfiguration().getGuiMenuBackgroundColor() );
685                 item.setForeground( getConfiguration().getGuiMenuTextColor() );
686             }
687             item.setSelected( is_selected );
688             item.addActionListener( this );
689         }
690     }
691
692     JMenuItem customizeJMenuItem( final JMenuItem jmi ) {
693         if ( jmi != null ) {
694             jmi.setFont( MainFrame.menu_font );
695             if ( !getConfiguration().isUseNativeUI() ) {
696                 jmi.setBackground( getConfiguration().getGuiMenuBackgroundColor() );
697                 jmi.setForeground( getConfiguration().getGuiMenuTextColor() );
698             }
699             jmi.addActionListener( this );
700         }
701         return jmi;
702     }
703
704     void customizeRadioButtonMenuItem( final JRadioButtonMenuItem item, final boolean is_selected ) {
705         if ( item != null ) {
706             item.setFont( MainFrame.menu_font );
707             if ( !getConfiguration().isUseNativeUI() ) {
708                 item.setBackground( getConfiguration().getGuiMenuBackgroundColor() );
709                 item.setForeground( getConfiguration().getGuiMenuTextColor() );
710             }
711             item.setSelected( is_selected );
712             item.addActionListener( this );
713         }
714     }
715
716     void displayBasicInformation() {
717         if ( ( _mainpanel.getCurrentPhylogeny() != null ) && !_mainpanel.getCurrentPhylogeny().isEmpty() ) {
718             String title = "Basic Information";
719             if ( !ForesterUtil.isEmpty( _mainpanel.getCurrentPhylogeny().getName() ) ) {
720                 title = _mainpanel.getCurrentPhylogeny().getName() + " " + title;
721             }
722             showTextFrame( AptxUtil.createBasicInformation( _mainpanel.getCurrentPhylogeny() ), title );
723         }
724     }
725
726     void exceptionOccuredDuringOpenFile( final Exception e ) {
727         try {
728             _mainpanel.getCurrentTreePanel().setArrowCursor();
729         }
730         catch ( final Exception ex ) {
731             // Do nothing.
732         }
733         JOptionPane.showMessageDialog( this,
734                                        ForesterUtil.wordWrap( e.getLocalizedMessage(), 80 ),
735                                        "Error during File|Open",
736                                        JOptionPane.ERROR_MESSAGE );
737     }
738
739     void exceptionOccuredDuringSaveAs( final Exception e ) {
740         try {
741             _mainpanel.getCurrentTreePanel().setArrowCursor();
742         }
743         catch ( final Exception ex ) {
744             // Do nothing.
745         }
746         JOptionPane.showMessageDialog( this, "Exception" + e, "Error during File|SaveAs", JOptionPane.ERROR_MESSAGE );
747     }
748
749     boolean GAndSDoHaveMoreThanOneSpeciesInComman( final Phylogeny gene_tree ) {
750         if ( ( gene_tree == null ) || gene_tree.isEmpty() ) {
751             JOptionPane.showMessageDialog( this,
752                                            "Gene tree and species tree have no species in common.",
753                                            "Error during SDI",
754                                            JOptionPane.ERROR_MESSAGE );
755             return false;
756         }
757         else if ( gene_tree.getNumberOfExternalNodes() < 2 ) {
758             JOptionPane.showMessageDialog( this,
759                                            "Gene tree and species tree have only one species in common.",
760                                            "Error during SDI",
761                                            JOptionPane.ERROR_MESSAGE );
762             return false;
763         }
764         else {
765             return true;
766         }
767     }
768
769     TreePanel getCurrentTreePanel() {
770         return getMainPanel().getCurrentTreePanel();
771     }
772
773     JMenu getHelpMenu() {
774         return _help_jmenu;
775     }
776
777     JCheckBoxMenuItem getlabelDirectionCbmi() {
778         return _label_direction_cbmi;
779     }
780
781     JMenuBar getMenuBarOfMainFrame() {
782         return _jmenubar;
783     }
784
785     void help( final Map<String, WebLink> weblinks ) {
786         final StringBuilder sb = new StringBuilder();
787         sb.append( "Display options\n" );
788         sb.append( "-------------------\n" );
789         sb.append( "Use the checkboxes to select types of information to display on the tree.\n\n" );
790         sb.append( "Clickable tree nodes\n" );
791         sb.append( "--------------------\n" );
792         sb.append( "Tree nodes can be clicked, the action is determined by the 'click on node to' menu\n" );
793         sb.append( "or by right clicking:\n" );
794         sb.append( "o  Display Node Data -- display information for a node\n" );
795         sb.append( "o  Collapse/Uncollapse -- collapse and uncollapse subtree from clicked node\n" );
796         sb.append( "o  Root/Reroot -- change tree root to clicked node\n" );
797         sb.append( "o  Sub/Super Tree -- toggle between subtree from clicked node and whole tree\n" );
798         sb.append( "o  Swap Descendants -- switch descendant on either side of clicked node\n" );
799         sb.append( "o  Colorize Subtree -- color a subtree\n" );
800         sb.append( "o  Open Sequence Web -- launch a web browser to display sequence information\n" );
801         sb.append( "o  Open Taxonomy Web -- launch a web browser to display taxonomy information\n" );
802         sb.append( "-  there may be additional choices depending on this particular setup\n\n" );
803         sb.append( "Right clicking on a node always displays the information of a node.\n\n" );
804         sb.append( "Zooming\n" );
805         sb.append( "---------\n" );
806         sb.append( "The mouse wheel and the plus and minus keys control zooming.\n" );
807         sb.append( "Mouse wheel+Ctrl changes the text size.\n" );
808         sb.append( "Mouse wheel+Shift controls zooming in vertical direction only.\n" );
809         sb.append( "Use the buttons on the control panel to zoom the tree in and out, horizontally or vertically.\n" );
810         sb.append( "The entire tree can be fitted into the window by clicking the \"F\" button, or by pressing F, Delete, or Home.\n" );
811         sb.append( "The up, down, left, and right keys can be used to move the visible part (if zoomed in).\n" );
812         sb.append( "Up, down, left, and right+Shift can be used to control zooming horizontally and vertically.\n" );
813         sb.append( "Plus and minus keys+Ctrl change the text size; F+Ctrl, Delete+Ctrl, or Home+Ctrl resets it.\n\n" );
814         sb.append( "Quick tree manipulation:\n" );
815         sb.append( "------------------------\n" );
816         sb.append( "Order Subtrees -- order the tree by branch length\n" );
817         sb.append( "Uncollapse All -- uncollapse any and all collapsed branches\n\n" );
818         sb.append( "Memory problems (Java heap space error)\n" );
819         sb.append( "---------------------------------------\n" );
820         sb.append( "Since the Java default memory allocation is quite small, it might by necessary (for trees\n" );
821         sb.append( "with more than approximately 5000 external nodes) to increase the memory which Java can use, with\n" );
822         sb.append( "the '-Xmx' Java command line option. For example:\n" );
823         sb.append( "java -Xms32m -Xmx256m -cp path\\to\\forester.jar org.forester.archaeopteryx.Archaeopteryx\n\n" );
824         if ( ( weblinks != null ) && ( weblinks.size() > 0 ) ) {
825             sb.append( "Active web links\n" );
826             sb.append( "--------------------\n" );
827             for( final String key : weblinks.keySet() ) {
828                 sb.append( " " + weblinks.get( key ).toString() + "\n" );
829             }
830         }
831         // + "General remarks\n"
832         // + "---------------\n"
833         // +
834         // "o  The application version permits copying to the clipboard \n"
835         // +
836         // "    in the \"View\"|\"View as ...\" frame (either by control-c or button press).\n"
837         // +
838         // "o  Changes made to a subtree affect this subtree and its subtrees,\n"
839         // + "    but not any of its parent tree(s).\n"
840         // +
841         // "o  Archaeopteryx tries to detect whether the numerical values in a NH tree\n"
842         // +
843         // "    are likely to be bootstrap values instead of branch length values.\n\n"
844         // +
845         // " Remarks regarding SDI (Speciation Duplication Inference):\n"
846         // +
847         // "o  Each external node of the gene tree (in display) needs to be associated with\n"
848         // +
849         // "    a species: either directly through the \"Species\" field, or the species\n"
850         // +
851         // "    is part of the sequence name in the form \"XXXX_SPECIES\"\n"
852         // +
853         // "    (e.g. \"ACON_DROME\" or \"ACON_DROME/123-4489\" which is also acceptable).\n"
854         // +
855         // "o  A species tree for each species of the gene tree needs to be loaded with\n"
856         // +
857         // "   \"SDI\"|\"Load species tree\" prior the SDI execution.\n"
858         // +
859         // "o  !External nodes of the gene tree associated with species not present in\n"
860         // +
861         // "    the species tree are REMOVED prior to SDI execution!\n"
862         // +
863         // "o  Both the gene tree and the species tree must be completely binary.\n"
864         // +
865         // "o  Duplications and speciations are a function of the position of the root.\n"
866         // +
867         // "    Hence, after each manual \"Root/Reroot\"ing some duplications will be\n"
868         // + "    incorrect and need to be inferred again\n"
869         // +
870         // "    with: \"SDI\"|\"SDI (Speciation Duplication Inference)\n\n"
871         sb.append( "\n" );
872         sb.append( "phyloXML\n" );
873         sb.append( "-------------------\n" );
874         sb.append( "Reference: " + Constants.PHYLOXML_REFERENCE + "\n" );
875         sb.append( "Website: " + Constants.PHYLOXML_WEB_SITE + "\n" );
876         sb.append( "Version: " + ForesterConstants.PHYLO_XML_VERSION + "\n" );
877         sb.append( "\n" );
878         sb.append( "For more information: http://www.phylosoft.org/archaeopteryx/\n" );
879         sb.append( "Email: " + Constants.AUTHOR_EMAIL + "\n\n" );
880         TextFrame.instantiate( sb.toString(), "Help", _textframes );
881     }
882
883     void initializeTypeMenu( final Options options ) {
884         setTypeMenuToAllUnselected();
885         switch ( options.getPhylogenyGraphicsType() ) {
886             case CONVEX:
887                 _convex_type_cbmi.setSelected( true );
888                 break;
889             case CURVED:
890                 _curved_type_cbmi.setSelected( true );
891                 break;
892             case EURO_STYLE:
893                 _euro_type_cbmi.setSelected( true );
894                 break;
895             case ROUNDED:
896                 _rounded_type_cbmi.setSelected( true );
897                 break;
898             case TRIANGULAR:
899                 _triangular_type_cbmi.setSelected( true );
900                 break;
901             case UNROOTED:
902                 _unrooted_type_cbmi.setSelected( true );
903                 break;
904             case CIRCULAR:
905                 _circular_type_cbmi.setSelected( true );
906                 break;
907             default:
908                 _rectangular_type_cbmi.setSelected( true );
909                 break;
910         }
911     }
912
913     boolean isSubtreeDisplayed() {
914         if ( getCurrentTreePanel() != null ) {
915             if ( getCurrentTreePanel().isCurrentTreeIsSubtree() ) {
916                 JOptionPane
917                         .showMessageDialog( this,
918                                             "This operation can only be performed on a complete tree, not on the currently displayed sub-tree only.",
919                                             "Operation can not be exectuted on a sub-tree",
920                                             JOptionPane.WARNING_MESSAGE );
921                 return true;
922             }
923         }
924         return false;
925     }
926
927     void midpointRoot() {
928         if ( _mainpanel.getCurrentTreePanel() != null ) {
929             _mainpanel.getCurrentTreePanel().midpointRoot();
930         }
931     }
932
933     abstract void readPhylogeniesFromURL();
934
935     void readPhylogeniesFromWebservice( final int i ) {
936         final UrlTreeReader reader = new UrlTreeReader( this, i );
937         new Thread( reader ).start();
938     }
939
940     void removeAllTextFrames() {
941         for( final TextFrame tf : _textframes ) {
942             if ( tf != null ) {
943                 tf.close();
944             }
945         }
946         _textframes.clear();
947     }
948
949     void setConfiguration( final Configuration configuration ) {
950         _configuration = configuration;
951     }
952
953     void setInferenceManager( final InferenceManager i ) {
954         _inference_manager = i;
955     }
956
957     void setOptions( final Options options ) {
958         _options = options;
959     }
960
961     void setSelectedTypeInTypeMenu( final PHYLOGENY_GRAPHICS_TYPE type ) {
962         setTypeMenuToAllUnselected();
963         switch ( type ) {
964             case CIRCULAR:
965                 _circular_type_cbmi.setSelected( true );
966                 break;
967             case CONVEX:
968                 _convex_type_cbmi.setSelected( true );
969                 break;
970             case CURVED:
971                 _curved_type_cbmi.setSelected( true );
972                 break;
973             case EURO_STYLE:
974                 _euro_type_cbmi.setSelected( true );
975                 break;
976             case ROUNDED:
977                 _rounded_type_cbmi.setSelected( true );
978                 break;
979             case RECTANGULAR:
980                 _rectangular_type_cbmi.setSelected( true );
981                 break;
982             case TRIANGULAR:
983                 _triangular_type_cbmi.setSelected( true );
984                 break;
985             case UNROOTED:
986                 _unrooted_type_cbmi.setSelected( true );
987                 break;
988             default:
989                 throw new IllegalArgumentException( "unknown type: " + type );
990         }
991     }
992
993     void setTypeMenuToAllUnselected() {
994         _convex_type_cbmi.setSelected( false );
995         _curved_type_cbmi.setSelected( false );
996         _euro_type_cbmi.setSelected( false );
997         _rounded_type_cbmi.setSelected( false );
998         _triangular_type_cbmi.setSelected( false );
999         _rectangular_type_cbmi.setSelected( false );
1000         _unrooted_type_cbmi.setSelected( false );
1001         _circular_type_cbmi.setSelected( false );
1002     }
1003
1004     void switchColors() {
1005         final TreeColorSet colorset = _mainpanel.getTreeColorSet();
1006         final ColorSchemeChooser csc = new ColorSchemeChooser( getMainPanel(), colorset );
1007         csc.setVisible( true );
1008     }
1009
1010     void taxColor() {
1011         if ( _mainpanel.getCurrentTreePanel() != null ) {
1012             _mainpanel.getCurrentTreePanel().taxColor();
1013         }
1014     }
1015
1016     void typeChanged( final Object o ) {
1017         updateTypeCheckboxes( getOptions(), o );
1018         updateOptions( getOptions() );
1019         if ( getCurrentTreePanel() != null ) {
1020             final PHYLOGENY_GRAPHICS_TYPE previous_type = getCurrentTreePanel().getPhylogenyGraphicsType();
1021             final PHYLOGENY_GRAPHICS_TYPE new_type = getOptions().getPhylogenyGraphicsType();
1022             if ( ( ( previous_type == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) && ( new_type != PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) )
1023                     || ( ( previous_type == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) && ( new_type != PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) )
1024                     || ( ( previous_type != PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) && ( new_type == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) )
1025                     || ( ( previous_type != PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) && ( new_type == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) ) ) {
1026                 getCurrentTreePanel().getControlPanel().showWhole();
1027             }
1028             if ( getCurrentTreePanel().isPhyHasBranchLengths() && ( new_type != PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) ) {
1029                 getCurrentTreePanel().getControlPanel().setDrawPhylogramEnabled( true );
1030             }
1031             else {
1032                 getCurrentTreePanel().getControlPanel().setDrawPhylogramEnabled( false );
1033             }
1034             getCurrentTreePanel().setPhylogenyGraphicsType( getOptions().getPhylogenyGraphicsType() );
1035             updateScreenTextAntialias( getMainPanel().getTreePanels() );
1036             if ( getCurrentTreePanel().getControlPanel().getDynamicallyHideData() != null ) {
1037                 if ( new_type == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) {
1038                     getCurrentTreePanel().getControlPanel().getDynamicallyHideData().setEnabled( false );
1039                 }
1040                 else {
1041                     getCurrentTreePanel().getControlPanel().getDynamicallyHideData().setEnabled( true );
1042                 }
1043             }
1044         }
1045     }
1046
1047     void updateOptions( final Options options ) {
1048         options.setAntialiasScreen( ( _screen_antialias_cbmi != null ) && _screen_antialias_cbmi.isSelected() );
1049         options.setBackgroundColorGradient( ( _background_gradient_cbmi != null )
1050                 && _background_gradient_cbmi.isSelected() );
1051         options.setShowDomainLabels( ( _show_domain_labels != null ) && _show_domain_labels.isSelected() );
1052         options.setAbbreviateScientificTaxonNames( ( _abbreviate_scientific_names != null )
1053                 && _abbreviate_scientific_names.isSelected() );
1054         options.setColorLabelsSameAsParentBranch( ( _color_labels_same_as_parent_branch != null )
1055                 && _color_labels_same_as_parent_branch.isSelected() );
1056         options.setShowDefaultNodeShapes( ( _show_default_node_shapes_cbmi != null )
1057                 && _show_default_node_shapes_cbmi.isSelected() );
1058         options.setTaxonomyColorizeNodeShapes( ( _taxonomy_colorize_node_shapes_cbmi != null )
1059                 && _taxonomy_colorize_node_shapes_cbmi.isSelected() );
1060         if ( ( _non_lined_up_cladograms_rbmi != null ) && ( _non_lined_up_cladograms_rbmi.isSelected() ) ) {
1061             options.setCladogramType( CLADOGRAM_TYPE.NON_LINED_UP );
1062         }
1063         else if ( ( _uniform_cladograms_rbmi != null ) && ( _uniform_cladograms_rbmi.isSelected() ) ) {
1064             options.setCladogramType( CLADOGRAM_TYPE.TOTAL_NODE_SUM_DEP );
1065         }
1066         else if ( ( _ext_node_dependent_cladogram_rbmi != null ) && ( _ext_node_dependent_cladogram_rbmi.isSelected() ) ) {
1067             options.setCladogramType( CLADOGRAM_TYPE.EXT_NODE_SUM_DEP );
1068         }
1069         options.setSearchCaseSensitive( ( _search_case_senstive_cbmi != null )
1070                 && _search_case_senstive_cbmi.isSelected() );
1071         if ( ( _show_scale_cbmi != null ) && _show_scale_cbmi.isEnabled() ) {
1072             options.setShowScale( _show_scale_cbmi.isSelected() );
1073         }
1074         if ( _label_direction_cbmi != null ) {
1075             if ( _label_direction_cbmi.isSelected() ) {
1076                 options.setNodeLabelDirection( NODE_LABEL_DIRECTION.RADIAL );
1077             }
1078             else {
1079                 options.setNodeLabelDirection( NODE_LABEL_DIRECTION.HORIZONTAL );
1080             }
1081         }
1082         options.setShowOverview( ( _show_overview_cbmi != null ) && _show_overview_cbmi.isSelected() );
1083         options.setShowConfidenceStddev( ( _show_confidence_stddev_cbmi != null )
1084                 && _show_confidence_stddev_cbmi.isSelected() );
1085         if ( ( _show_branch_length_values_cbmi != null ) && _show_branch_length_values_cbmi.isEnabled() ) {
1086             options.setShowBranchLengthValues( _show_branch_length_values_cbmi.isSelected() );
1087         }
1088         options.setPrintUsingActualSize( ( _print_using_actual_size_cbmi != null )
1089                 && ( _print_using_actual_size_cbmi.isSelected() ) );
1090         options.setGraphicsExportUsingActualSize( ( _graphics_export_using_actual_size_cbmi != null )
1091                 && ( _graphics_export_using_actual_size_cbmi.isSelected() ) );
1092         options.setAntialiasPrint( ( _antialias_print_cbmi != null ) && _antialias_print_cbmi.isSelected() );
1093         if ( ( _use_brackets_for_conf_in_nh_export_cbmi != null )
1094                 && _use_brackets_for_conf_in_nh_export_cbmi.isSelected() ) {
1095             options.setNhConversionSupportValueStyle( NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS );
1096         }
1097         else if ( ( _use_internal_names_for_conf_in_nh_export_cbmi != null )
1098                 && _use_internal_names_for_conf_in_nh_export_cbmi.isSelected() ) {
1099             options.setNhConversionSupportValueStyle( NH_CONVERSION_SUPPORT_VALUE_STYLE.AS_INTERNAL_NODE_NAMES );
1100         }
1101         else {
1102             options.setNhConversionSupportValueStyle( NH_CONVERSION_SUPPORT_VALUE_STYLE.NONE );
1103         }
1104         options.setPrintBlackAndWhite( ( _print_black_and_white_cbmi != null )
1105                 && _print_black_and_white_cbmi.isSelected() );
1106         options.setInternalNumberAreConfidenceForNhParsing( ( _internal_number_are_confidence_for_nh_parsing_cbmi != null )
1107                 && _internal_number_are_confidence_for_nh_parsing_cbmi.isSelected() );
1108         options.setExtractPfamTaxonomyCodesInNhParsing( ( _extract_pfam_style_tax_codes_cbmi != null )
1109                 && _extract_pfam_style_tax_codes_cbmi.isSelected() );
1110         options.setReplaceUnderscoresInNhParsing( ( _replace_underscores_cbmi != null )
1111                 && _replace_underscores_cbmi.isSelected() );
1112         options.setMatchWholeTermsOnly( ( _search_whole_words_only_cbmi != null )
1113                 && _search_whole_words_only_cbmi.isSelected() );
1114         options.setInverseSearchResult( ( _inverse_search_result_cbmi != null )
1115                 && _inverse_search_result_cbmi.isSelected() );
1116         if ( _graphics_export_visible_only_cbmi != null ) {
1117             options.setGraphicsExportVisibleOnly( _graphics_export_visible_only_cbmi.isSelected() );
1118             if ( _graphics_export_visible_only_cbmi.isSelected() && ( _graphics_export_using_actual_size_cbmi != null ) ) {
1119                 _graphics_export_using_actual_size_cbmi.setSelected( true );
1120                 _graphics_export_using_actual_size_cbmi.setEnabled( false );
1121             }
1122             else {
1123                 _graphics_export_using_actual_size_cbmi.setEnabled( true );
1124             }
1125         }
1126         if ( ( _rectangular_type_cbmi != null ) && _rectangular_type_cbmi.isSelected() ) {
1127             options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR );
1128         }
1129         else if ( ( _triangular_type_cbmi != null ) && _triangular_type_cbmi.isSelected() ) {
1130             options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.TRIANGULAR );
1131         }
1132         else if ( ( _curved_type_cbmi != null ) && _curved_type_cbmi.isSelected() ) {
1133             options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CURVED );
1134         }
1135         else if ( ( _convex_type_cbmi != null ) && _convex_type_cbmi.isSelected() ) {
1136             options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CONVEX );
1137         }
1138         else if ( ( _euro_type_cbmi != null ) && _euro_type_cbmi.isSelected() ) {
1139             options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE );
1140         }
1141         else if ( ( _rounded_type_cbmi != null ) && _rounded_type_cbmi.isSelected() ) {
1142             options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.ROUNDED );
1143         }
1144         else if ( ( _unrooted_type_cbmi != null ) && _unrooted_type_cbmi.isSelected() ) {
1145             options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.UNROOTED );
1146         }
1147         else if ( ( _circular_type_cbmi != null ) && _circular_type_cbmi.isSelected() ) {
1148             options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CIRCULAR );
1149         }
1150     }
1151
1152     void updateTypeCheckboxes( final Options options, final Object o ) {
1153         setTypeMenuToAllUnselected();
1154         ( ( JCheckBoxMenuItem ) o ).setSelected( true );
1155     }
1156
1157     void viewAsNexus() {
1158         if ( ( _mainpanel.getCurrentPhylogeny() != null ) && !_mainpanel.getCurrentPhylogeny().isEmpty() ) {
1159             String title = "Nexus";
1160             if ( !ForesterUtil.isEmpty( _mainpanel.getCurrentPhylogeny().getName() ) ) {
1161                 title = _mainpanel.getCurrentPhylogeny().getName() + " " + title;
1162             }
1163             showTextFrame( _mainpanel.getCurrentPhylogeny().toNexus( getOptions().getNhConversionSupportValueStyle() ),
1164                            title );
1165         }
1166     }
1167
1168     void viewAsNH() {
1169         if ( ( _mainpanel.getCurrentPhylogeny() != null ) && !_mainpanel.getCurrentPhylogeny().isEmpty() ) {
1170             String title = "New Hampshire";
1171             if ( !ForesterUtil.isEmpty( _mainpanel.getCurrentPhylogeny().getName() ) ) {
1172                 title = _mainpanel.getCurrentPhylogeny().getName() + " " + title;
1173             }
1174             showTextFrame( _mainpanel.getCurrentPhylogeny()
1175                                    .toNewHampshire( false, getOptions().getNhConversionSupportValueStyle() ),
1176                            title );
1177         }
1178     }
1179
1180     void viewAsNHX() {
1181         if ( ( _mainpanel.getCurrentPhylogeny() != null ) && !_mainpanel.getCurrentPhylogeny().isEmpty() ) {
1182             String title = "NHX";
1183             if ( !ForesterUtil.isEmpty( _mainpanel.getCurrentPhylogeny().getName() ) ) {
1184                 title = _mainpanel.getCurrentPhylogeny().getName() + " " + title;
1185             }
1186             showTextFrame( _mainpanel.getCurrentPhylogeny().toNewHampshireX(), title );
1187         }
1188     }
1189
1190     void viewAsXML() {
1191         if ( ( _mainpanel.getCurrentPhylogeny() != null ) && !_mainpanel.getCurrentPhylogeny().isEmpty() ) {
1192             String title = "phyloXML";
1193             if ( !ForesterUtil.isEmpty( _mainpanel.getCurrentPhylogeny().getName() ) ) {
1194                 title = _mainpanel.getCurrentPhylogeny().getName() + " " + title;
1195             }
1196             showTextFrame( _mainpanel.getCurrentPhylogeny().toPhyloXML( 0 ), title );
1197         }
1198     }
1199
1200     private void annotateSequences() {
1201         if ( getCurrentTreePanel() != null ) {
1202             final Set<Integer> nodes = getCurrentTreePanel().getFoundNodes();
1203             if ( ( nodes == null ) || nodes.isEmpty() ) {
1204                 JOptionPane
1205                         .showMessageDialog( this,
1206                                             "Need to select nodes, either via direct selection or via the \"Search\" function",
1207                                             "No nodes selected for annotation",
1208                                             JOptionPane.ERROR_MESSAGE );
1209                 return;
1210             }
1211             final Phylogeny phy = getMainPanel().getCurrentPhylogeny();
1212             if ( ( phy != null ) && !phy.isEmpty() ) {
1213                 final JTextField xField = new JTextField( 10 );
1214                 final JTextField yField = new JTextField( 20 );
1215                 xField.setText( ForesterUtil.isEmpty( getPreviousNodeAnnotationReference() ) ? ""
1216                         : getPreviousNodeAnnotationReference() );
1217                 final JPanel myPanel = new JPanel();
1218                 myPanel.add( new JLabel( "Reference " ) );
1219                 myPanel.add( xField );
1220                 myPanel.add( Box.createHorizontalStrut( 15 ) );
1221                 myPanel.add( new JLabel( "Description " ) );
1222                 myPanel.add( yField );
1223                 final int result = JOptionPane.showConfirmDialog( null,
1224                                                                   myPanel,
1225                                                                   "Enter the sequence annotation(s) for the "
1226                                                                           + nodes.size() + " selected nodes",
1227                                                                   JOptionPane.OK_CANCEL_OPTION );
1228                 if ( result == JOptionPane.OK_OPTION ) {
1229                     String ref = xField.getText();
1230                     String desc = yField.getText();
1231                     if ( ref != null ) {
1232                         ref = ref.trim();
1233                         ref = ref.replaceAll( "\\s+", " " );
1234                     }
1235                     if ( desc != null ) {
1236                         desc = desc.trim();
1237                         desc = desc.replaceAll( "\\s+", " " );
1238                     }
1239                     if ( ref != null ) {
1240                         setPreviousNodeAnnotationReference( ref );
1241                     }
1242                     if ( !ForesterUtil.isEmpty( ref ) || !ForesterUtil.isEmpty( desc ) ) {
1243                         for( final Integer id : nodes ) {
1244                             final PhylogenyNode n = phy.getNode( id );
1245                             ForesterUtil.ensurePresenceOfSequence( n );
1246                             final Annotation ann = ForesterUtil.isEmpty( ref ) ? new Annotation()
1247                                     : new Annotation( ref );
1248                             if ( !ForesterUtil.isEmpty( desc ) ) {
1249                                 ann.setDesc( desc );
1250                             }
1251                             n.getNodeData().getSequence().addAnnotation( ann );
1252                         }
1253                     }
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 }