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.NodeVisualData.NodeFill;
69 import org.forester.phylogeny.data.NodeVisualData.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                   _save_item;
144     JMenuItem                   _save_all_item;
145     JMenuItem                   _close_item;
146     JMenuItem                   _exit_item;
147     JMenuItem                   _new_item;
148     // tools menu:
149     JMenuItem                   _midpoint_root_item;
150     JMenuItem                   _taxcolor_item;
151     JMenuItem                   _confcolor_item;
152     JMenuItem                   _color_rank_jmi;
153     JMenuItem                   _collapse_species_specific_subtrees;
154     JMenuItem                   _collapse_below_threshold;                                                                                                                                                                                    //TODO implememt me
155     JMenuItem                   _obtain_detailed_taxonomic_information_jmi;
156     JMenuItem                   _obtain_detailed_taxonomic_information_deleting_jmi;
157     JMenuItem                   _obtain_seq_information_jmi;
158     JMenuItem                   _move_node_names_to_tax_sn_jmi;
159     JMenuItem                   _move_node_names_to_seq_names_jmi;
160     JMenuItem                   _extract_tax_code_from_node_names_jmi;
161     JMenuItem                   _annotate_item;
162     JMenuItem                   _remove_branch_color_item;
163     JMenuItem                   _remove_visual_styles_item;
164     // font size menu:
165     JMenuItem                   _super_tiny_fonts_item;
166     JMenuItem                   _tiny_fonts_item;
167     JMenuItem                   _small_fonts_item;
168     JMenuItem                   _medium_fonts_item;
169     JMenuItem                   _large_fonts_item;
170     // options menu:
171     // _  screen and print
172     JMenuItem                   _choose_font_mi;
173     JMenuItem                   _switch_colors_mi;
174     JCheckBoxMenuItem           _label_direction_cbmi;
175     // _  screen display
176     JCheckBoxMenuItem           _screen_antialias_cbmi;
177     JCheckBoxMenuItem           _background_gradient_cbmi;
178     JRadioButtonMenuItem        _non_lined_up_cladograms_rbmi;
179     JRadioButtonMenuItem        _uniform_cladograms_rbmi;
180     JRadioButtonMenuItem        _ext_node_dependent_cladogram_rbmi;
181     JCheckBoxMenuItem           _show_branch_length_values_cbmi;
182     JCheckBoxMenuItem           _color_by_taxonomic_group_cbmi;
183     JCheckBoxMenuItem           _show_scale_cbmi;                                                                                                                                                                                             //TODO fix me
184     JCheckBoxMenuItem           _show_overview_cbmi;
185     JCheckBoxMenuItem           _show_domain_labels;
186     JCheckBoxMenuItem           _show_annotation_ref_source;
187     JCheckBoxMenuItem           _abbreviate_scientific_names;
188     JCheckBoxMenuItem           _color_labels_same_as_parent_branch;
189     JMenuItem                   _overview_placment_mi;
190     JMenuItem                   _choose_minimal_confidence_mi;
191     JCheckBoxMenuItem           _show_default_node_shapes_internal_cbmi;
192     JCheckBoxMenuItem           _show_default_node_shapes_external_cbmi;
193     JMenuItem                   _cycle_node_shape_mi;
194     JMenuItem                   _cycle_node_fill_mi;
195     JMenuItem                   _choose_node_size_mi;
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           _allow_errors_in_distance_to_parent_cbmi;
213     JCheckBoxMenuItem           _use_brackets_for_conf_in_nh_export_cbmi;
214     JCheckBoxMenuItem           _use_internal_names_for_conf_in_nh_export_cbmi;
215     // _  search
216     JCheckBoxMenuItem           _search_case_senstive_cbmi;
217     JCheckBoxMenuItem           _search_whole_words_only_cbmi;
218     JCheckBoxMenuItem           _inverse_search_result_cbmi;
219     // type menu:
220     JMenu                       _type_menu;
221     JCheckBoxMenuItem           _rectangular_type_cbmi;
222     JCheckBoxMenuItem           _triangular_type_cbmi;
223     JCheckBoxMenuItem           _curved_type_cbmi;
224     JCheckBoxMenuItem           _convex_type_cbmi;
225     JCheckBoxMenuItem           _euro_type_cbmi;
226     JCheckBoxMenuItem           _rounded_type_cbmi;
227     JCheckBoxMenuItem           _unrooted_type_cbmi;
228     JCheckBoxMenuItem           _circular_type_cbmi;
229     // view as text menu:
230     JMenuItem                   _view_as_NH_item;
231     JMenuItem                   _view_as_XML_item;
232     JMenuItem                   _view_as_nexus_item;
233     JMenuItem                   _display_basic_information_item;
234     // help menu:
235     JMenuItem                   _about_item;
236     JMenuItem                   _help_item;
237     JMenuItem                   _website_item;
238     JMenuItem                   _phyloxml_website_item;
239     JMenuItem                   _phyloxml_ref_item;
240     JMenuItem                   _aptx_ref_item;
241     // process menu:
242     JMenu                       _process_menu;
243     // Handy pointers to child components:
244     MainPanel                   _mainpanel;
245     Container                   _contentpane;
246     final LinkedList<TextFrame> _textframes                             = new LinkedList<TextFrame>();                                                                                                                                         ;
247     Configuration               _configuration;
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 == _exit_item ) {
273             close();
274         }
275         else if ( o == _gsdi_item ) {
276             if ( isSubtreeDisplayed() ) {
277                 return;
278             }
279             executeGSDI();
280         }
281         else if ( o == _gsdir_item ) {
282             if ( isSubtreeDisplayed() ) {
283                 return;
284             }
285             executeGSDIR();
286         }
287         else if ( o == _taxcolor_item ) {
288             taxColor();
289         }
290         else if ( o == _confcolor_item ) {
291             confColor();
292         }
293         else if ( o == _color_rank_jmi ) {
294             colorRank();
295         }
296         else if ( o == _collapse_species_specific_subtrees ) {
297             if ( isSubtreeDisplayed() ) {
298                 return;
299             }
300             if ( getCurrentTreePanel() != null ) {
301                 getCurrentTreePanel().collapseSpeciesSpecificSubtrees();
302             }
303         }
304         else if ( o == _remove_branch_color_item ) {
305             if ( isSubtreeDisplayed() ) {
306                 return;
307             }
308             removeBranchColors();
309         }
310         else if ( o == _remove_visual_styles_item ) {
311             if ( isSubtreeDisplayed() ) {
312                 return;
313             }
314             removeVisualStyles();
315         }
316         else if ( o == _midpoint_root_item ) {
317             if ( isSubtreeDisplayed() ) {
318                 return;
319             }
320             midpointRoot();
321         }
322         else if ( o == _annotate_item ) {
323             annotateSequences();
324         }
325         else if ( o == _switch_colors_mi ) {
326             switchColors();
327         }
328         else if ( o == _display_basic_information_item ) {
329             displayBasicInformation( getCurrentTreePanel().getTreeFile() );
330         }
331         else if ( o == _view_as_NH_item ) {
332             viewAsNH();
333         }
334         else if ( o == _view_as_XML_item ) {
335             viewAsXML();
336         }
337         else if ( o == _view_as_nexus_item ) {
338             viewAsNexus();
339         }
340         else if ( o == _super_tiny_fonts_item ) {
341             if ( getCurrentTreePanel() != null ) {
342                 getCurrentTreePanel().setSuperTinyFonts();
343                 getCurrentTreePanel().repaint();
344             }
345         }
346         else if ( o == _tiny_fonts_item ) {
347             if ( getCurrentTreePanel() != null ) {
348                 getCurrentTreePanel().setTinyFonts();
349                 getCurrentTreePanel().repaint();
350             }
351         }
352         else if ( o == _small_fonts_item ) {
353             if ( getCurrentTreePanel() != null ) {
354                 getCurrentTreePanel().setSmallFonts();
355                 getCurrentTreePanel().repaint();
356             }
357         }
358         else if ( o == _medium_fonts_item ) {
359             if ( getCurrentTreePanel() != null ) {
360                 getCurrentTreePanel().setMediumFonts();
361                 getCurrentTreePanel().repaint();
362             }
363         }
364         else if ( o == _large_fonts_item ) {
365             if ( getCurrentTreePanel() != null ) {
366                 getCurrentTreePanel().setLargeFonts();
367                 getCurrentTreePanel().repaint();
368             }
369         }
370         else if ( o == _choose_font_mi ) {
371             chooseFont();
372         }
373         else if ( o == _choose_minimal_confidence_mi ) {
374             chooseMinimalConfidence();
375         }
376         else if ( o == _choose_node_size_mi ) {
377             chooseNodeSize( getOptions(), this );
378         }
379         else if ( o == _overview_placment_mi ) {
380             MainFrame.cycleOverview( getOptions(), getCurrentTreePanel() );
381         }
382         else if ( o == _cycle_node_fill_mi ) {
383             MainFrame.cycleNodeFill( getOptions(), getCurrentTreePanel() );
384         }
385         else if ( o == _cycle_node_shape_mi ) {
386             MainFrame.cycleNodeShape( getOptions(), getCurrentTreePanel() );
387         }
388         else if ( o == _screen_antialias_cbmi ) {
389             updateOptions( getOptions() );
390             updateScreenTextAntialias( getMainPanel().getTreePanels() );
391         }
392         else if ( o == _background_gradient_cbmi ) {
393             updateOptions( getOptions() );
394         }
395         else if ( o == _show_domain_labels ) {
396             updateOptions( getOptions() );
397         }
398         else if ( o == _show_annotation_ref_source ) {
399             updateOptions( getOptions() );
400         }
401         else if ( o == _abbreviate_scientific_names ) {
402             updateOptions( getOptions() );
403         }
404         else if ( o == _color_labels_same_as_parent_branch ) {
405             updateOptions( getOptions() );
406         }
407         else if ( o == _show_default_node_shapes_internal_cbmi ) {
408             updateOptions( getOptions() );
409         }
410         else if ( o == _show_default_node_shapes_external_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().search0();
428             getMainPanel().getControlPanel().search1();
429         }
430         else if ( o == _search_whole_words_only_cbmi ) {
431             updateOptions( getOptions() );
432             getMainPanel().getControlPanel().search0();
433             getMainPanel().getControlPanel().search1();
434         }
435         else if ( o == _inverse_search_result_cbmi ) {
436             updateOptions( getOptions() );
437             getMainPanel().getControlPanel().search0();
438             getMainPanel().getControlPanel().search1();
439         }
440         else if ( o == _show_scale_cbmi ) {
441             updateOptions( getOptions() );
442         }
443         else if ( o == _show_branch_length_values_cbmi ) {
444             updateOptions( getOptions() );
445         }
446         else if ( o == _color_by_taxonomic_group_cbmi ) {
447             updateOptions( getOptions() );
448         }
449         else if ( o == _show_confidence_stddev_cbmi ) {
450             updateOptions( getOptions() );
451         }
452         else if ( o == _use_brackets_for_conf_in_nh_export_cbmi ) {
453             if ( _use_brackets_for_conf_in_nh_export_cbmi.isSelected() ) {
454                 _use_internal_names_for_conf_in_nh_export_cbmi.setSelected( false );
455             }
456             updateOptions( getOptions() );
457         }
458         else if ( o == _use_internal_names_for_conf_in_nh_export_cbmi ) {
459             if ( _use_internal_names_for_conf_in_nh_export_cbmi.isSelected() ) {
460                 _use_brackets_for_conf_in_nh_export_cbmi.setSelected( false );
461             }
462             updateOptions( getOptions() );
463         }
464         else if ( o == _label_direction_cbmi ) {
465             updateOptions( getOptions() );
466         }
467         else if ( o == _show_overview_cbmi ) {
468             updateOptions( getOptions() );
469             if ( getCurrentTreePanel() != null ) {
470                 getCurrentTreePanel().updateOvSizes();
471             }
472         }
473         else if ( ( o == _rectangular_type_cbmi ) || ( o == _triangular_type_cbmi ) || ( o == _curved_type_cbmi )
474                 || ( o == _convex_type_cbmi ) || ( o == _euro_type_cbmi ) || ( o == _rounded_type_cbmi )
475                 || ( o == _unrooted_type_cbmi ) || ( o == _circular_type_cbmi ) ) {
476             typeChanged( o );
477         }
478         else if ( o == _about_item ) {
479             about();
480         }
481         else if ( o == _help_item ) {
482             help();
483         }
484         else if ( o == _website_item ) {
485             try {
486                 AptxUtil.openWebsite( Constants.APTX_WEB_SITE, is_applet, applet );
487             }
488             catch ( final IOException e1 ) {
489                 ForesterUtil.printErrorMessage( Constants.PRG_NAME, e1.toString() );
490             }
491         }
492         else if ( o == _phyloxml_website_item ) {
493             try {
494                 AptxUtil.openWebsite( Constants.PHYLOXML_WEB_SITE, is_applet, applet );
495             }
496             catch ( final IOException e1 ) {
497                 ForesterUtil.printErrorMessage( Constants.PRG_NAME, e1.toString() );
498             }
499         }
500         else if ( o == _aptx_ref_item ) {
501             try {
502                 AptxUtil.openWebsite( Constants.APTX_REFERENCE_URL, is_applet, applet );
503             }
504             catch ( final IOException e1 ) {
505                 ForesterUtil.printErrorMessage( Constants.PRG_NAME, e1.toString() );
506             }
507         }
508         else if ( o == _phyloxml_ref_item ) {
509             try {
510                 AptxUtil.openWebsite( Constants.PHYLOXML_REFERENCE_URL, is_applet, applet );
511             }
512             catch ( final IOException e1 ) {
513                 ForesterUtil.printErrorMessage( Constants.PRG_NAME, e1.toString() );
514             }
515         }
516         else {
517             if ( _load_phylogeny_from_webservice_menu_items != null ) {
518                 for( int i = 0; i < _load_phylogeny_from_webservice_menu_items.length; ++i ) {
519                     if ( o == _load_phylogeny_from_webservice_menu_items[ i ] ) {
520                         readPhylogeniesFromWebservice( i );
521                     }
522                 }
523             }
524         }
525         _contentpane.repaint();
526     }
527
528     public Configuration getConfiguration() {
529         return _configuration;
530     }
531
532     /**
533      * This method returns the current external node data which
534      * has been selected by the user by clicking the "Return ..."
535      * menu item. This method is expected to be called from Javascript or
536      * something like it.
537      * 
538      * @return current external node data as String
539      */
540     public String getCurrentExternalNodesDataBuffer() {
541         return getCurrentTreePanel().getCurrentExternalNodesDataBufferAsString();
542     }
543
544     public int getCurrentExternalNodesDataBufferChangeCounter() {
545         return getCurrentTreePanel().getCurrentExternalNodesDataBufferChangeCounter();
546     }
547
548     public int getCurrentExternalNodesDataBufferLength() {
549         return getCurrentTreePanel().getCurrentExternalNodesDataBufferAsString().length();
550     }
551
552     public InferenceManager getInferenceManager() {
553         return _inference_manager;
554     }
555
556     public MainPanel getMainPanel() {
557         return _mainpanel;
558     }
559
560     public Options getOptions() {
561         return _options;
562     }
563
564     public ProcessPool getProcessPool() {
565         return _process_pool;
566     }
567
568     public void showTextFrame( final String s, final String title ) {
569         checkTextFrames();
570         _textframes.addLast( TextFrame.instantiate( s, title, _textframes ) );
571     }
572
573     public void showWhole() {
574         _mainpanel.getControlPanel().showWhole();
575     }
576
577     public void updateProcessMenu() {
578         // In general Swing is not thread safe.
579         // See "Swing's Threading Policy".
580         SwingUtilities.invokeLater( new Runnable() {
581
582             @Override
583             public void run() {
584                 doUpdateProcessMenu();
585             }
586         } );
587     }
588
589     void activateSaveAllIfNeeded() {
590         if ( ( getMainPanel().getTabbedPane() != null ) && ( getMainPanel().getTabbedPane().getTabCount() > 1 ) ) {
591             _save_all_item.setEnabled( true );
592         }
593         else {
594             _save_all_item.setEnabled( false );
595         }
596     }
597
598     void buildFileMenu() {
599         _file_jmenu = createMenu( "File", getConfiguration() );
600         _file_jmenu.add( _exit_item = new JMenuItem( "Exit" ) );
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     void readPhylogeniesFromWebservice( final int i ) {
1151         final UrlTreeReader reader = new UrlTreeReader( this, i );
1152         new Thread( reader ).start();
1153     }
1154
1155     void removeAllTextFrames() {
1156         for( final TextFrame tf : _textframes ) {
1157             if ( tf != null ) {
1158                 tf.close();
1159             }
1160         }
1161         _textframes.clear();
1162     }
1163
1164     void setConfiguration( final Configuration configuration ) {
1165         _configuration = configuration;
1166     }
1167
1168     void setInferenceManager( final InferenceManager i ) {
1169         _inference_manager = i;
1170     }
1171
1172     void setOptions( final Options options ) {
1173         _options = options;
1174     }
1175
1176     void setSelectedTypeInTypeMenu( final PHYLOGENY_GRAPHICS_TYPE type ) {
1177         setTypeMenuToAllUnselected();
1178         switch ( type ) {
1179             case CIRCULAR:
1180                 _circular_type_cbmi.setSelected( true );
1181                 break;
1182             case CONVEX:
1183                 _convex_type_cbmi.setSelected( true );
1184                 break;
1185             case CURVED:
1186                 _curved_type_cbmi.setSelected( true );
1187                 break;
1188             case EURO_STYLE:
1189                 _euro_type_cbmi.setSelected( true );
1190                 break;
1191             case ROUNDED:
1192                 _rounded_type_cbmi.setSelected( true );
1193                 break;
1194             case RECTANGULAR:
1195                 _rectangular_type_cbmi.setSelected( true );
1196                 break;
1197             case TRIANGULAR:
1198                 _triangular_type_cbmi.setSelected( true );
1199                 break;
1200             case UNROOTED:
1201                 _unrooted_type_cbmi.setSelected( true );
1202                 break;
1203             default:
1204                 throw new IllegalArgumentException( "unknown type: " + type );
1205         }
1206     }
1207
1208     final void setSpeciesTree( final Phylogeny species_tree ) {
1209         _species_tree = species_tree;
1210     }
1211
1212     void setTypeMenuToAllUnselected() {
1213         _convex_type_cbmi.setSelected( false );
1214         _curved_type_cbmi.setSelected( false );
1215         _euro_type_cbmi.setSelected( false );
1216         _rounded_type_cbmi.setSelected( false );
1217         _triangular_type_cbmi.setSelected( false );
1218         _rectangular_type_cbmi.setSelected( false );
1219         _unrooted_type_cbmi.setSelected( false );
1220         _circular_type_cbmi.setSelected( false );
1221     }
1222
1223     void switchColors() {
1224         final TreeColorSet colorset = _mainpanel.getTreeColorSet();
1225         final ColorSchemeChooser csc = new ColorSchemeChooser( getMainPanel(), colorset );
1226         csc.setVisible( true );
1227     }
1228
1229     void taxColor() {
1230         if ( _mainpanel.getCurrentTreePanel() != null ) {
1231             _mainpanel.getCurrentTreePanel().taxColor();
1232         }
1233     }
1234
1235     void typeChanged( final Object o ) {
1236         updateTypeCheckboxes( getOptions(), o );
1237         updateOptions( getOptions() );
1238         if ( getCurrentTreePanel() != null ) {
1239             final PHYLOGENY_GRAPHICS_TYPE previous_type = getCurrentTreePanel().getPhylogenyGraphicsType();
1240             final PHYLOGENY_GRAPHICS_TYPE new_type = getOptions().getPhylogenyGraphicsType();
1241             if ( ( ( previous_type == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) && ( new_type != PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) )
1242                     || ( ( previous_type == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) && ( new_type != PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) )
1243                     || ( ( 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                 getCurrentTreePanel().getControlPanel().showWhole();
1246             }
1247             if ( getCurrentTreePanel().isPhyHasBranchLengths() && ( new_type != PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) ) {
1248                 getCurrentTreePanel().getControlPanel().setDrawPhylogramEnabled( true );
1249             }
1250             else {
1251                 getCurrentTreePanel().getControlPanel().setDrawPhylogramEnabled( false );
1252             }
1253             getCurrentTreePanel().setPhylogenyGraphicsType( getOptions().getPhylogenyGraphicsType() );
1254             updateScreenTextAntialias( getMainPanel().getTreePanels() );
1255             if ( getCurrentTreePanel().getControlPanel().getDynamicallyHideData() != null ) {
1256                 if ( new_type == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) {
1257                     getCurrentTreePanel().getControlPanel().getDynamicallyHideData().setEnabled( false );
1258                 }
1259                 else {
1260                     getCurrentTreePanel().getControlPanel().getDynamicallyHideData().setEnabled( true );
1261                 }
1262             }
1263         }
1264     }
1265
1266     void updateOptions( final Options options ) {
1267         options.setAntialiasScreen( ( _screen_antialias_cbmi != null ) && _screen_antialias_cbmi.isSelected() );
1268         options.setBackgroundColorGradient( ( _background_gradient_cbmi != null )
1269                 && _background_gradient_cbmi.isSelected() );
1270         options.setShowDomainLabels( ( _show_domain_labels != null ) && _show_domain_labels.isSelected() );
1271         options.setShowAnnotationRefSource( ( _show_annotation_ref_source != null )
1272                 && _show_annotation_ref_source.isSelected() );
1273         options.setAbbreviateScientificTaxonNames( ( _abbreviate_scientific_names != null )
1274                 && _abbreviate_scientific_names.isSelected() );
1275         options.setColorLabelsSameAsParentBranch( ( _color_labels_same_as_parent_branch != null )
1276                 && _color_labels_same_as_parent_branch.isSelected() );
1277         options.setShowDefaultNodeShapesInternal( ( _show_default_node_shapes_internal_cbmi != null )
1278                 && _show_default_node_shapes_internal_cbmi.isSelected() );
1279         options.setShowDefaultNodeShapesExternal( ( _show_default_node_shapes_external_cbmi != null )
1280                 && _show_default_node_shapes_external_cbmi.isSelected() );
1281         if ( ( _non_lined_up_cladograms_rbmi != null ) && ( _non_lined_up_cladograms_rbmi.isSelected() ) ) {
1282             options.setCladogramType( CLADOGRAM_TYPE.NON_LINED_UP );
1283         }
1284         else if ( ( _uniform_cladograms_rbmi != null ) && ( _uniform_cladograms_rbmi.isSelected() ) ) {
1285             options.setCladogramType( CLADOGRAM_TYPE.TOTAL_NODE_SUM_DEP );
1286         }
1287         else if ( ( _ext_node_dependent_cladogram_rbmi != null ) && ( _ext_node_dependent_cladogram_rbmi.isSelected() ) ) {
1288             options.setCladogramType( CLADOGRAM_TYPE.EXT_NODE_SUM_DEP );
1289         }
1290         options.setSearchCaseSensitive( ( _search_case_senstive_cbmi != null )
1291                 && _search_case_senstive_cbmi.isSelected() );
1292         if ( ( _show_scale_cbmi != null ) && _show_scale_cbmi.isEnabled() ) {
1293             options.setShowScale( _show_scale_cbmi.isSelected() );
1294         }
1295         if ( _label_direction_cbmi != null ) {
1296             if ( _label_direction_cbmi.isSelected() ) {
1297                 options.setNodeLabelDirection( NODE_LABEL_DIRECTION.RADIAL );
1298             }
1299             else {
1300                 options.setNodeLabelDirection( NODE_LABEL_DIRECTION.HORIZONTAL );
1301             }
1302         }
1303         options.setShowOverview( ( _show_overview_cbmi != null ) && _show_overview_cbmi.isSelected() );
1304         options.setShowConfidenceStddev( ( _show_confidence_stddev_cbmi != null )
1305                 && _show_confidence_stddev_cbmi.isSelected() );
1306         if ( ( _show_branch_length_values_cbmi != null ) && _show_branch_length_values_cbmi.isEnabled() ) {
1307             options.setShowBranchLengthValues( _show_branch_length_values_cbmi.isSelected() );
1308         }
1309         if ( ( _color_by_taxonomic_group_cbmi != null ) && _color_by_taxonomic_group_cbmi.isEnabled() ) {
1310             options.setColorByTaxonomicGroup( _color_by_taxonomic_group_cbmi.isSelected() );
1311         }
1312         options.setPrintUsingActualSize( ( _print_using_actual_size_cbmi != null )
1313                 && ( _print_using_actual_size_cbmi.isSelected() ) );
1314         options.setGraphicsExportUsingActualSize( ( _graphics_export_using_actual_size_cbmi != null )
1315                 && ( _graphics_export_using_actual_size_cbmi.isSelected() ) );
1316         options.setAntialiasPrint( ( _antialias_print_cbmi != null ) && _antialias_print_cbmi.isSelected() );
1317         if ( ( _use_brackets_for_conf_in_nh_export_cbmi != null )
1318                 && _use_brackets_for_conf_in_nh_export_cbmi.isSelected() ) {
1319             options.setNhConversionSupportValueStyle( NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS );
1320         }
1321         else if ( ( _use_internal_names_for_conf_in_nh_export_cbmi != null )
1322                 && _use_internal_names_for_conf_in_nh_export_cbmi.isSelected() ) {
1323             options.setNhConversionSupportValueStyle( NH_CONVERSION_SUPPORT_VALUE_STYLE.AS_INTERNAL_NODE_NAMES );
1324         }
1325         else {
1326             options.setNhConversionSupportValueStyle( NH_CONVERSION_SUPPORT_VALUE_STYLE.NONE );
1327         }
1328         options.setPrintBlackAndWhite( ( _print_black_and_white_cbmi != null )
1329                 && _print_black_and_white_cbmi.isSelected() );
1330         options.setInternalNumberAreConfidenceForNhParsing( ( _internal_number_are_confidence_for_nh_parsing_cbmi != null )
1331                 && _internal_number_are_confidence_for_nh_parsing_cbmi.isSelected() );
1332         if ( ( _extract_taxonomy_pfam_strict_rbmi != null ) && _extract_taxonomy_pfam_strict_rbmi.isSelected() ) {
1333             options.setTaxonomyExtraction( TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1334         }
1335         else if ( ( _extract_taxonomy_pfam_relaxed_rbmi != null ) && _extract_taxonomy_pfam_relaxed_rbmi.isSelected() ) {
1336             options.setTaxonomyExtraction( TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
1337         }
1338         else if ( ( _extract_taxonomy_agressive_rbmi != null ) && _extract_taxonomy_agressive_rbmi.isSelected() ) {
1339             options.setTaxonomyExtraction( TAXONOMY_EXTRACTION.AGGRESSIVE );
1340         }
1341         else if ( ( _extract_taxonomy_no_rbmi != null ) && _extract_taxonomy_no_rbmi.isSelected() ) {
1342             options.setTaxonomyExtraction( TAXONOMY_EXTRACTION.NO );
1343         }
1344         options.setReplaceUnderscoresInNhParsing( ( _replace_underscores_cbmi != null )
1345                 && _replace_underscores_cbmi.isSelected() );
1346         options.setAllowErrorsInDistanceToParent( ( _allow_errors_in_distance_to_parent_cbmi != null )
1347                 && _allow_errors_in_distance_to_parent_cbmi.isSelected() );
1348         options.setMatchWholeTermsOnly( ( _search_whole_words_only_cbmi != null )
1349                 && _search_whole_words_only_cbmi.isSelected() );
1350         options.setInverseSearchResult( ( _inverse_search_result_cbmi != null )
1351                 && _inverse_search_result_cbmi.isSelected() );
1352         if ( _graphics_export_visible_only_cbmi != null ) {
1353             options.setGraphicsExportVisibleOnly( _graphics_export_visible_only_cbmi.isSelected() );
1354             if ( _graphics_export_visible_only_cbmi.isSelected() && ( _graphics_export_using_actual_size_cbmi != null ) ) {
1355                 _graphics_export_using_actual_size_cbmi.setSelected( true );
1356                 _graphics_export_using_actual_size_cbmi.setEnabled( false );
1357             }
1358             else {
1359                 _graphics_export_using_actual_size_cbmi.setEnabled( true );
1360             }
1361         }
1362         if ( ( _rectangular_type_cbmi != null ) && _rectangular_type_cbmi.isSelected() ) {
1363             options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR );
1364         }
1365         else if ( ( _triangular_type_cbmi != null ) && _triangular_type_cbmi.isSelected() ) {
1366             options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.TRIANGULAR );
1367         }
1368         else if ( ( _curved_type_cbmi != null ) && _curved_type_cbmi.isSelected() ) {
1369             options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CURVED );
1370         }
1371         else if ( ( _convex_type_cbmi != null ) && _convex_type_cbmi.isSelected() ) {
1372             options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CONVEX );
1373         }
1374         else if ( ( _euro_type_cbmi != null ) && _euro_type_cbmi.isSelected() ) {
1375             options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE );
1376         }
1377         else if ( ( _rounded_type_cbmi != null ) && _rounded_type_cbmi.isSelected() ) {
1378             options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.ROUNDED );
1379         }
1380         else if ( ( _unrooted_type_cbmi != null ) && _unrooted_type_cbmi.isSelected() ) {
1381             options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.UNROOTED );
1382         }
1383         else if ( ( _circular_type_cbmi != null ) && _circular_type_cbmi.isSelected() ) {
1384             options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CIRCULAR );
1385         }
1386     }
1387
1388     void updateTypeCheckboxes( final Options options, final Object o ) {
1389         setTypeMenuToAllUnselected();
1390         ( ( JCheckBoxMenuItem ) o ).setSelected( true );
1391     }
1392
1393     void viewAsNexus() {
1394         if ( ( _mainpanel.getCurrentPhylogeny() != null ) && !_mainpanel.getCurrentPhylogeny().isEmpty() ) {
1395             String title = "Nexus";
1396             if ( !ForesterUtil.isEmpty( _mainpanel.getCurrentPhylogeny().getName() ) ) {
1397                 title = "\"" + getMainPanel().getCurrentPhylogeny().getName() + "\" in " + title;
1398             }
1399             showTextFrame( _mainpanel.getCurrentPhylogeny().toNexus( getOptions().getNhConversionSupportValueStyle() ),
1400                            title );
1401         }
1402     }
1403
1404     void viewAsNH() {
1405         if ( ( _mainpanel.getCurrentPhylogeny() != null ) && !_mainpanel.getCurrentPhylogeny().isEmpty() ) {
1406             String title = "New Hampshire";
1407             if ( !ForesterUtil.isEmpty( _mainpanel.getCurrentPhylogeny().getName() ) ) {
1408                 title = "\"" + getMainPanel().getCurrentPhylogeny().getName() + "\" in " + title;
1409             }
1410             showTextFrame( _mainpanel.getCurrentPhylogeny()
1411                                    .toNewHampshire( false, getOptions().getNhConversionSupportValueStyle() ),
1412                            title );
1413         }
1414     }
1415
1416     void viewAsXML() {
1417         if ( ( _mainpanel.getCurrentPhylogeny() != null ) && !_mainpanel.getCurrentPhylogeny().isEmpty() ) {
1418             String title = "phyloXML";
1419             if ( !ForesterUtil.isEmpty( _mainpanel.getCurrentPhylogeny().getName() ) ) {
1420                 title = "\"" + getMainPanel().getCurrentPhylogeny().getName() + "\" in " + title;
1421             }
1422             showTextFrame( _mainpanel.getCurrentPhylogeny().toPhyloXML( 0 ), title );
1423         }
1424     }
1425
1426     private void annotateSequences() {
1427         if ( getCurrentTreePanel() != null ) {
1428             final Set<Long> nodes = getCurrentTreePanel().getFoundNodes0();
1429             if ( ( nodes == null ) || nodes.isEmpty() ) {
1430                 JOptionPane
1431                         .showMessageDialog( this,
1432                                             "Need to select nodes, either via direct selection or via the \"Search\" function",
1433                                             "No nodes selected for annotation",
1434                                             JOptionPane.ERROR_MESSAGE );
1435                 return;
1436             }
1437             final Phylogeny phy = getMainPanel().getCurrentPhylogeny();
1438             if ( ( phy != null ) && !phy.isEmpty() ) {
1439                 final JTextField ref_field = new JTextField( 10 );
1440                 final JTextField desc_filed = new JTextField( 20 );
1441                 ref_field.setText( ForesterUtil.isEmpty( getPreviousNodeAnnotationReference() ) ? ""
1442                         : getPreviousNodeAnnotationReference() );
1443                 final JPanel my_panel = new JPanel();
1444                 my_panel.add( new JLabel( "Reference " ) );
1445                 my_panel.add( ref_field );
1446                 my_panel.add( Box.createHorizontalStrut( 15 ) );
1447                 my_panel.add( new JLabel( "Description " ) );
1448                 my_panel.add( desc_filed );
1449                 final int result = JOptionPane.showConfirmDialog( null,
1450                                                                   my_panel,
1451                                                                   "Enter the sequence annotation(s) for the "
1452                                                                           + nodes.size() + " selected nodes",
1453                                                                   JOptionPane.OK_CANCEL_OPTION );
1454                 if ( result == JOptionPane.OK_OPTION ) {
1455                     String ref = ref_field.getText();
1456                     String desc = desc_filed.getText();
1457                     if ( !ForesterUtil.isEmpty( ref ) ) {
1458                         ref = ref.trim();
1459                         ref = ref.replaceAll( "\\s+", " " );
1460                         if ( ( ref.indexOf( ':' ) < 1 ) || ( ref.indexOf( ':' ) > ref.length() - 2 )
1461                                 || ( ref.length() < 3 ) ) {
1462                             JOptionPane.showMessageDialog( this,
1463                                                            "Reference needs to be in the form of \"GO:1234567\"",
1464                                                            "Illegal Format for Annotation Reference",
1465                                                            JOptionPane.ERROR_MESSAGE );
1466                             return;
1467                         }
1468                     }
1469                     if ( ref != null ) {
1470                         setPreviousNodeAnnotationReference( ref );
1471                     }
1472                     if ( desc != null ) {
1473                         desc = desc.trim();
1474                         desc = desc.replaceAll( "\\s+", " " );
1475                     }
1476                     if ( !ForesterUtil.isEmpty( ref ) || !ForesterUtil.isEmpty( desc ) ) {
1477                         for( final Long id : nodes ) {
1478                             final PhylogenyNode n = phy.getNode( id );
1479                             ForesterUtil.ensurePresenceOfSequence( n );
1480                             final Annotation ann = ForesterUtil.isEmpty( ref ) ? new Annotation()
1481                                     : new Annotation( ref );
1482                             if ( !ForesterUtil.isEmpty( desc ) ) {
1483                                 ann.setDesc( desc );
1484                             }
1485                             n.getNodeData().getSequence().addAnnotation( ann );
1486                         }
1487                     }
1488                     getMainPanel().getControlPanel().showAnnotations();
1489                 }
1490             }
1491         }
1492     }
1493
1494     private void chooseFont() {
1495         final FontChooser fc = new FontChooser();
1496         fc.setFont( getMainPanel().getTreeFontSet().getLargeFont() );
1497         fc.showDialog( this, "Select the Base Font" );
1498         getMainPanel().getTreeFontSet().setBaseFont( fc.getFont() );
1499     }
1500
1501     private void chooseMinimalConfidence() {
1502         final String s = ( String ) JOptionPane
1503                 .showInputDialog( this,
1504                                   "Please enter the minimum for confidence values to be displayed.\n"
1505                                           + "[current value: " + getOptions().getMinConfidenceValue() + "]\n",
1506                                   "Minimal Confidence Value",
1507                                   JOptionPane.QUESTION_MESSAGE,
1508                                   null,
1509                                   null,
1510                                   getOptions().getMinConfidenceValue() );
1511         if ( !ForesterUtil.isEmpty( s ) ) {
1512             boolean success = true;
1513             double m = 0.0;
1514             final String m_str = s.trim();
1515             if ( !ForesterUtil.isEmpty( m_str ) ) {
1516                 try {
1517                     m = Double.parseDouble( m_str );
1518                 }
1519                 catch ( final Exception ex ) {
1520                     success = false;
1521                 }
1522             }
1523             else {
1524                 success = false;
1525             }
1526             if ( success && ( m >= 0.0 ) ) {
1527                 getOptions().setMinConfidenceValue( m );
1528             }
1529         }
1530     }
1531
1532     private void doUpdateProcessMenu() {
1533         if ( _process_pool.size() > 0 ) {
1534             if ( _process_menu == null ) {
1535                 _process_menu = createMenu( "", getConfiguration() );
1536                 _process_menu.setForeground( Color.RED );
1537             }
1538             _process_menu.removeAll();
1539             final String text = "processes running: " + _process_pool.size();
1540             _process_menu.setText( text );
1541             _jmenubar.add( _process_menu );
1542             for( int i = 0; i < _process_pool.size(); ++i ) {
1543                 final ProcessRunning p = _process_pool.getProcessByIndex( i );
1544                 _process_menu.add( customizeJMenuItem( new JMenuItem( p.getName() + " [" + p.getStart() + "]" ) ) );
1545             }
1546         }
1547         else {
1548             if ( _process_menu != null ) {
1549                 _process_menu.removeAll();
1550                 _jmenubar.remove( _process_menu );
1551             }
1552         }
1553         _jmenubar.validate();
1554         _jmenubar.repaint();
1555         repaint();
1556     }
1557
1558     private String getPreviousNodeAnnotationReference() {
1559         return _previous_node_annotation_ref;
1560     }
1561
1562     private void removeBranchColors() {
1563         if ( getMainPanel().getCurrentPhylogeny() != null ) {
1564             AptxUtil.removeBranchColors( getMainPanel().getCurrentPhylogeny() );
1565         }
1566     }
1567
1568     private void removeVisualStyles() {
1569         if ( getMainPanel().getCurrentPhylogeny() != null ) {
1570             AptxUtil.removeVisualStyles( getMainPanel().getCurrentPhylogeny() );
1571         }
1572     }
1573
1574     private void setPreviousNodeAnnotationReference( final String previous_node_annotation_ref ) {
1575         _previous_node_annotation_ref = previous_node_annotation_ref;
1576     }
1577
1578     /**
1579      * Display the about box.
1580      */
1581     static void about() {
1582         final StringBuffer about = new StringBuffer( "Archaeopteryx\nVersion " + Constants.VERSION + "\n" );
1583         about.append( "Copyright (C) 2013 Christian M. Zmasek\n" );
1584         about.append( "All Rights Reserved\n" );
1585         about.append( "License: GNU Lesser General Public License (LGPL)\n" );
1586         about.append( "Last modified: " + Constants.PRG_DATE + "\n" );
1587         about.append( "Based on: " + ForesterUtil.getForesterLibraryInformation() + "\n" );
1588         about.append( "phyloXML version : " + ForesterConstants.PHYLO_XML_VERSION + "\n" );
1589         about.append( "phyloXML location: " + ForesterConstants.PHYLO_XML_LOCATION + "\n" );
1590         if ( !ForesterUtil.isEmpty( ForesterUtil.JAVA_VERSION ) && !ForesterUtil.isEmpty( ForesterUtil.JAVA_VENDOR ) ) {
1591             about.append( "[your Java version: " + ForesterUtil.JAVA_VERSION + " " + ForesterUtil.JAVA_VENDOR + "]\n" );
1592         }
1593         if ( !ForesterUtil.isEmpty( ForesterUtil.OS_NAME ) && !ForesterUtil.isEmpty( ForesterUtil.OS_ARCH )
1594                 && !ForesterUtil.isEmpty( ForesterUtil.OS_VERSION ) ) {
1595             about.append( "[your OS: " + ForesterUtil.OS_NAME + " " + ForesterUtil.OS_ARCH + " "
1596                     + ForesterUtil.OS_VERSION + "]\n" );
1597         }
1598         final Runtime rt = java.lang.Runtime.getRuntime();
1599         final long free_memory = rt.freeMemory() / 1000000;
1600         final long total_memory = rt.totalMemory() / 1000000;
1601         about.append( "[free memory: " + free_memory + "MB, total memory: " + total_memory + "MB]\n" );
1602         about.append( "[locale: " + Locale.getDefault() + "]\n" );
1603         about.append( "References:\n" );
1604         about.append( Constants.PHYLOXML_REFERENCE_SHORT + "\n" );
1605         about.append( "For more information & download:\n" );
1606         about.append( Constants.APTX_WEB_SITE + "\n" );
1607         about.append( "Comments: " + Constants.AUTHOR_EMAIL );
1608         JOptionPane.showMessageDialog( null, about, Constants.PRG_NAME, JOptionPane.PLAIN_MESSAGE );
1609     }
1610
1611     static void chooseNodeSize( final Options options, final Component parent ) {
1612         final String s = ( String ) JOptionPane.showInputDialog( parent,
1613                                                                  "Please enter the default size for node shapes.\n"
1614                                                                          + "[current value: "
1615                                                                          + options.getDefaultNodeShapeSize() + "]\n",
1616                                                                  "Node Shape Size",
1617                                                                  JOptionPane.QUESTION_MESSAGE,
1618                                                                  null,
1619                                                                  null,
1620                                                                  options.getDefaultNodeShapeSize() );
1621         if ( !ForesterUtil.isEmpty( s ) ) {
1622             boolean success = true;
1623             double m = 0.0;
1624             final String m_str = s.trim();
1625             if ( !ForesterUtil.isEmpty( m_str ) ) {
1626                 try {
1627                     m = Double.parseDouble( m_str );
1628                 }
1629                 catch ( final Exception ex ) {
1630                     success = false;
1631                 }
1632             }
1633             else {
1634                 success = false;
1635             }
1636             if ( success && ( m >= 0.0 ) ) {
1637                 final short size = ForesterUtil.roundToShort( m );
1638                 if ( size >= 0.0 ) {
1639                     options.setDefaultNodeShapeSize( size );
1640                 }
1641             }
1642         }
1643     }
1644
1645     static String createCurrentFontDesc( final TreeFontSet tree_font_set ) {
1646         return tree_font_set.getLargeFont().getFamily() + " " + tree_font_set.getLargeFont().getSize();
1647     }
1648
1649     static JMenu createMenu( final String title, final Configuration conf ) {
1650         final JMenu jmenu = new JMenu( title );
1651         if ( !conf.isUseNativeUI() ) {
1652             jmenu.setFont( MainFrame.menu_font );
1653             jmenu.setBackground( conf.getGuiMenuBackgroundColor() );
1654             jmenu.setForeground( conf.getGuiMenuTextColor() );
1655         }
1656         return jmenu;
1657     }
1658
1659     static JMenuItem customizeMenuItemAsLabel( final JMenuItem label, final Configuration configuration ) {
1660         label.setFont( MainFrame.menu_font.deriveFont( Font.BOLD ) );
1661         if ( !configuration.isUseNativeUI() ) {
1662             label.setBackground( configuration.getGuiMenuBackgroundColor() );
1663             label.setForeground( configuration.getGuiMenuTextColor() );
1664             label.setOpaque( true );
1665         }
1666         label.setSelected( false );
1667         label.setEnabled( false );
1668         return label;
1669     }
1670
1671     static void cycleNodeFill( final Options op, final TreePanel tree_panel ) {
1672         switch ( op.getDefaultNodeFill() ) {
1673             case GRADIENT:
1674                 op.setDefaultNodeFill( NodeFill.SOLID );
1675                 break;
1676             case NONE:
1677                 op.setDefaultNodeFill( NodeFill.GRADIENT );
1678                 break;
1679             case SOLID:
1680                 op.setDefaultNodeFill( NodeFill.NONE );
1681                 break;
1682             default:
1683                 throw new RuntimeException( "unknown fill: " + op.getDefaultNodeFill() );
1684         }
1685     }
1686
1687     static void cycleNodeShape( final Options op, final TreePanel tree_panel ) {
1688         switch ( op.getDefaultNodeShape() ) {
1689             case CIRCLE:
1690                 op.setDefaultNodeShape( NodeShape.RECTANGLE );
1691                 break;
1692             case RECTANGLE:
1693                 op.setDefaultNodeShape( NodeShape.CIRCLE );
1694                 break;
1695             default:
1696                 throw new RuntimeException( "unknown shape: " + op.getDefaultNodeShape() );
1697         }
1698     }
1699
1700     static void cycleOverview( final Options op, final TreePanel tree_panel ) {
1701         switch ( op.getOvPlacement() ) {
1702             case LOWER_LEFT:
1703                 op.setOvPlacement( Options.OVERVIEW_PLACEMENT_TYPE.UPPER_LEFT );
1704                 break;
1705             case LOWER_RIGHT:
1706                 op.setOvPlacement( Options.OVERVIEW_PLACEMENT_TYPE.LOWER_LEFT );
1707                 break;
1708             case UPPER_LEFT:
1709                 op.setOvPlacement( Options.OVERVIEW_PLACEMENT_TYPE.UPPER_RIGHT );
1710                 break;
1711             case UPPER_RIGHT:
1712                 op.setOvPlacement( Options.OVERVIEW_PLACEMENT_TYPE.LOWER_RIGHT );
1713                 break;
1714             default:
1715                 throw new RuntimeException( "unknown placement: " + op.getOvPlacement() );
1716         }
1717         if ( tree_panel != null ) {
1718             tree_panel.updateOvSettings();
1719         }
1720     }
1721
1722     static void setCycleNodeFillMenuItem( final JMenuItem mi, final Options options ) {
1723         if ( ( options != null ) && ( options.getDefaultNodeFill() != null ) ) {
1724             mi.setText( "Cycle Node Shape Fill Type... (current: "
1725                     + options.getDefaultNodeFill().toString().toLowerCase() + ")" );
1726         }
1727         else {
1728             mi.setText( "Cycle Node Shape Fill Type..." );
1729         }
1730     }
1731
1732     static void setCycleNodeShapeMenuItem( final JMenuItem mi, final Options options ) {
1733         if ( ( options != null ) && ( options.getDefaultNodeShape() != null ) ) {
1734             mi.setText( "Cycle Node Shape Fill Type... (current: "
1735                     + options.getDefaultNodeShape().toString().toLowerCase() + ")" );
1736         }
1737         else {
1738             mi.setText( "Cycle Node Shape Fill Type..." );
1739         }
1740     }
1741
1742     static void setOvPlacementColorChooseMenuItem( final JMenuItem mi, final Options options ) {
1743         if ( ( options != null ) && ( options.getOvPlacement() != null ) ) {
1744             mi.setText( "Cycle Overview Placement... (current: " + options.getOvPlacement() + ")" );
1745         }
1746         else {
1747             mi.setText( "Cycle Overview Placement..." );
1748         }
1749     }
1750
1751     static void setTextColorChooseMenuItem( final JMenuItem mi, final TreePanel tree_panel ) {
1752         if ( ( tree_panel != null ) && ( tree_panel.getTreeColorSet() != null ) ) {
1753             mi.setText( "Select Color Scheme... (current: " + tree_panel.getTreeColorSet().getCurrentColorSchemeName()
1754                     + ")" );
1755         }
1756         else {
1757             mi.setText( "Select Color Scheme..." );
1758         }
1759     }
1760
1761     static void setTextForFontChooserMenuItem( final JMenuItem mi, final String font_desc ) {
1762         mi.setText( "Select Default Font... (current: " + font_desc + ")" );
1763     }
1764
1765     static void setTextMinSupportMenuItem( final JMenuItem mi, final Options options, final TreePanel current_tree_panel ) {
1766         if ( ( current_tree_panel == null ) || ( current_tree_panel.getPhylogeny() == null ) ) {
1767             mi.setEnabled( true );
1768         }
1769         else if ( AptxUtil.isHasAtLeastOneBranchWithSupportValues( current_tree_panel.getPhylogeny() ) ) {
1770             mi.setEnabled( true );
1771         }
1772         else {
1773             mi.setEnabled( false );
1774         }
1775         mi.setText( "Enter Min Confidence Value... (current: " + options.getMinConfidenceValue() + ")" );
1776     }
1777
1778     static void setTextNodeSizeMenuItem( final JMenuItem mi, final Options options ) {
1779         mi.setText( "Enter Default Node Shape Size... (current: " + options.getDefaultNodeShapeSize() + ")" );
1780     }
1781
1782     static void updateOptionsMenuDependingOnPhylogenyType( final MainPanel main_panel,
1783                                                            final JCheckBoxMenuItem scale,
1784                                                            final JCheckBoxMenuItem branch_lengths,
1785                                                            final JRadioButtonMenuItem non_lined_up,
1786                                                            final JRadioButtonMenuItem uniform_clado,
1787                                                            final JRadioButtonMenuItem nonuniform_clado,
1788                                                            final JCheckBoxMenuItem label_direction_cbmi ) {
1789         final TreePanel tree_panel = main_panel.getCurrentTreePanel();
1790         final ControlPanel control = main_panel.getControlPanel();
1791         final Options options = main_panel.getOptions();
1792         scale.setSelected( options.isShowScale() );
1793         branch_lengths.setSelected( options.isShowBranchLengthValues() );
1794         // non_lined_up.setSelected( options.isNonLinedUpCladogram() );
1795         if ( ( tree_panel != null ) && ( !tree_panel.isPhyHasBranchLengths() ) ) {
1796             scale.setSelected( false );
1797             scale.setEnabled( false );
1798             branch_lengths.setSelected( false );
1799             branch_lengths.setEnabled( false );
1800         }
1801         else if ( ( tree_panel != null ) && !control.isDrawPhylogram() ) {
1802             scale.setSelected( false );
1803             scale.setEnabled( false );
1804             branch_lengths.setEnabled( true );
1805         }
1806         else {
1807             scale.setEnabled( true );
1808             branch_lengths.setEnabled( true );
1809         }
1810         if ( ( tree_panel != null )
1811                 && ( ( tree_panel.getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.ROUNDED )
1812                         && ( tree_panel.getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE ) && ( tree_panel
1813                         .getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR ) ) ) {
1814             branch_lengths.setSelected( false );
1815             branch_lengths.setEnabled( false );
1816         }
1817         if ( tree_panel != null ) {
1818             if ( ( tree_panel.getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR )
1819                     || ( tree_panel.getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) ) {
1820                 non_lined_up.setEnabled( false );
1821                 uniform_clado.setEnabled( false );
1822                 nonuniform_clado.setEnabled( false );
1823             }
1824             else {
1825                 non_lined_up.setEnabled( true );
1826                 uniform_clado.setEnabled( true );
1827                 nonuniform_clado.setEnabled( true );
1828             }
1829         }
1830         else {
1831             if ( ( tree_panel != null )
1832                     && ( ( tree_panel.getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE ) && ( tree_panel
1833                             .getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR ) ) ) {
1834                 branch_lengths.setSelected( false );
1835                 branch_lengths.setEnabled( false );
1836             }
1837             if ( ( tree_panel != null )
1838                     && ( ( tree_panel.getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) || ( tree_panel
1839                             .getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) ) ) {
1840                 non_lined_up.setEnabled( false );
1841             }
1842             else {
1843                 // non_lined_up.setSelected( options.isNonLinedUpCladogram() );
1844                 non_lined_up.setEnabled( true );
1845             }
1846         }
1847         label_direction_cbmi.setEnabled( true );
1848         if ( tree_panel != null ) {
1849             if ( ( tree_panel.getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.UNROOTED )
1850                     && ( tree_panel.getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) ) {
1851                 label_direction_cbmi.setEnabled( false );
1852             }
1853             if ( tree_panel.getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) {
1854                 scale.setSelected( false );
1855                 scale.setEnabled( false );
1856             }
1857         }
1858     }
1859
1860     static void updateScreenTextAntialias( final List<TreePanel> treepanels ) {
1861         for( final TreePanel tree_panel : treepanels ) {
1862             tree_panel.setTextAntialias();
1863         }
1864     }
1865 }