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