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