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