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.IOException;
34 import java.util.LinkedList;
35 import java.util.List;
36 import java.util.Locale;
37 import java.util.NoSuchElementException;
38 import java.util.Set;
39
40 import javax.swing.Box;
41 import javax.swing.JApplet;
42 import javax.swing.JCheckBoxMenuItem;
43 import javax.swing.JFrame;
44 import javax.swing.JLabel;
45 import javax.swing.JMenu;
46 import javax.swing.JMenuBar;
47 import javax.swing.JMenuItem;
48 import javax.swing.JOptionPane;
49 import javax.swing.JPanel;
50 import javax.swing.JRadioButtonMenuItem;
51 import javax.swing.JTextField;
52 import javax.swing.SwingUtilities;
53
54 import org.forester.archaeopteryx.Options.CLADOGRAM_TYPE;
55 import org.forester.archaeopteryx.Options.NODE_LABEL_DIRECTION;
56 import org.forester.archaeopteryx.Options.PHYLOGENY_GRAPHICS_TYPE;
57 import org.forester.archaeopteryx.tools.InferenceManager;
58 import org.forester.archaeopteryx.tools.ProcessPool;
59 import org.forester.archaeopteryx.tools.ProcessRunning;
60 import org.forester.io.parsers.nhx.NHXParser.TAXONOMY_EXTRACTION;
61 import org.forester.phylogeny.Phylogeny;
62 import org.forester.phylogeny.PhylogenyMethods;
63 import org.forester.phylogeny.PhylogenyMethods.DESCENDANT_SORT_PRIORITY;
64 import org.forester.phylogeny.PhylogenyNode;
65 import org.forester.phylogeny.PhylogenyNode.NH_CONVERSION_SUPPORT_VALUE_STYLE;
66 import org.forester.phylogeny.data.Annotation;
67 import org.forester.phylogeny.data.NodeVisualization.NodeFill;
68 import org.forester.phylogeny.data.NodeVisualization.NodeShape;
69 import org.forester.sdi.GSDI;
70 import org.forester.sdi.GSDIR;
71 import org.forester.sdi.SDIException;
72 import org.forester.util.ForesterConstants;
73 import org.forester.util.ForesterUtil;
74
75 public abstract class MainFrame extends JFrame implements ActionListener {
76
77     static final String         USE_MOUSEWHEEL_SHIFT_TO_ROTATE          = "In this display type, use mousewheel + Shift to rotate [or A and S]";
78     static final String         PHYLOXML_REF_TOOL_TIP                   = Constants.PHYLOXML_REFERENCE;                                                                                                                                       //TODO //FIXME
79     static final String         APTX_REF_TOOL_TIP                       = Constants.APTX_REFERENCE;
80     private static final long   serialVersionUID                        = 3655000897845508358L;
81     final static Font           menu_font                               = new Font( Configuration.getDefaultFontFamilyName(),
82                                                                                     Font.PLAIN,
83                                                                                     10 );
84     static final String         TYPE_MENU_HEADER                        = "Type";
85     static final String         RECTANGULAR_TYPE_CBMI_LABEL             = "Rectangular";
86     static final String         EURO_TYPE_CBMI_LABEL                    = "Euro Type";
87     static final String         CURVED_TYPE_CBMI_LABEL                  = "Curved";
88     static final String         TRIANGULAR_TYPE_CBMI_LABEL              = "Triangular";
89     static final String         CONVEX_TYPE_CBMI_LABEL                  = "Convex";
90     static final String         ROUNDED_TYPE_CBMI_LABEL                 = "Rounded";
91     static final String         UNROOTED_TYPE_CBMI_LABEL                = "Unrooted (alpha)";                                                                                                                                                 //TODO
92     static final String         CIRCULAR_TYPE_CBMI_LABEL                = "Circular (alpha)";                                                                                                                                                 //TODO
93     static final String         OPTIONS_HEADER                          = "Options";
94     static final String         SEARCH_SUBHEADER                        = "Search:";
95     static final String         DISPLAY_SUBHEADER                       = "Display:";
96     static final String         SEARCH_TERMS_ONLY_LABEL                 = "Match Complete Terms Only";
97     static final String         SEARCH_CASE_SENSITIVE_LABEL             = "Case Sensitive";
98     static final String         INVERSE_SEARCH_RESULT_LABEL             = "Negate Result";
99     static final String         DISPLAY_BRANCH_LENGTH_VALUES_LABEL      = "Display Branch Length Values";
100     static final String COLOR_BY_TAXONOMIC_GROUP = "Color by Taxonomic Group";
101     static final String         DISPLAY_SCALE_LABEL                     = "Display Scale";
102     static final String         NON_LINED_UP_CLADOGRAMS_LABEL           = "Non-Lined Up Cladograms";
103     static final String         UNIFORM_CLADOGRAMS_LABEL                = "Total Node Sum Dependent Cladograms";
104     static final String         LABEL_DIRECTION_LABEL                   = "Radial Labels";
105     static final String         LABEL_DIRECTION_TIP                     = "To use radial node labels in radial and unrooted display types";
106     static final String         SCREEN_ANTIALIAS_LABEL                  = "Antialias";
107     static final String         COLOR_LABELS_LABEL                      = "Color Labels Same as Parent Branch";
108     static final String         BG_GRAD_LABEL                           = "Background Color Gradient";
109     static final String         DISPLAY_NODE_BOXES_LABEL_EXT            = "Show External Node Shapes";
110     static final String         DISPLAY_NODE_BOXES_LABEL_INT            = "Show Internal Node Shapes";
111     static final String         SHOW_OVERVIEW_LABEL                     = "Show Overview";
112     static final String         FONT_SIZE_MENU_LABEL                    = "Font Size";
113     static final String         NONUNIFORM_CLADOGRAMS_LABEL             = "External Node Sum Dependent Cladograms";
114     static final String         SHOW_DOMAIN_LABELS_LABEL                = "Show Domain Labels";
115     static final String         SHOW_ANN_REF_SOURCE_LABEL               = "Show Seq Annotation Ref Sources";
116     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";
117     static final String         ABBREV_SN_LABEL                         = "Abbreviate Scientific Taxonomic Names";
118     static final String         TAXONOMY_COLORIZE_NODE_SHAPES_LABEL     = "Colorize Node Shapes According to Taxonomy";
119     static final String         CYCLE_NODE_SHAPE_LABEL                  = "Cycle Node Shapes";
120     static final String         CYCLE_NODE_FILL_LABEL                   = "Cycle Node Fill Type";
121     static final String         CHOOSE_NODE_SIZE_LABEL                  = "Choose Node Shape Size";
122     static final String         SHOW_CONF_STDDEV_LABEL                  = "Show Confidence Standard Deviations";
123     static final String         USE_BRACKETS_FOR_CONF_IN_NH_LABEL       = "Use Brackets for Confidence Values";
124     static final String         USE_INTERNAL_NAMES_FOR_CONF_IN_NH_LABEL = "Use Internal Node Names for Confidence Values";
125     static final String         SHOW_BASIC_TREE_INFORMATION_LABEL       = "Show Basic Tree Information";
126     JMenuBar                    _jmenubar;
127     JMenu                       _file_jmenu;
128     JMenu                       _tools_menu;
129     JMenu                       _view_jmenu;
130     JMenu                       _options_jmenu;
131     JMenu                       _font_size_menu;
132     JMenu                       _help_jmenu;
133     JMenuItem[]                 _load_phylogeny_from_webservice_menu_items;
134     // Analysis menu
135     JMenu                       _analysis_menu;
136     JMenuItem                   _load_species_tree_item;
137     JMenuItem                   _gsdi_item;
138     JMenuItem                   _gsdir_item;
139     JMenuItem                   _lineage_inference;
140     // file menu:
141     JMenuItem                   _open_item;
142     JMenuItem                   _open_url_item;
143     JMenuItem                   _save_item;
144     JMenuItem                   _save_all_item;
145     JMenuItem                   _close_item;
146     JMenuItem                   _exit_item;
147     JMenuItem                   _new_item;
148     // tools menu:
149     JMenuItem                   _midpoint_root_item;
150     JMenuItem                   _taxcolor_item;
151     JMenuItem                   _confcolor_item;
152     JMenuItem                   _color_rank_jmi;
153     JMenuItem                   _collapse_species_specific_subtrees;
154     JMenuItem                   _collapse_below_threshold;                                                                                                                                                                                    //TODO implememt me
155     JMenuItem                   _obtain_detailed_taxonomic_information_jmi;
156     JMenuItem                   _obtain_detailed_taxonomic_information_deleting_jmi;
157     JMenuItem                   _obtain_seq_information_jmi;
158     JMenuItem                   _move_node_names_to_tax_sn_jmi;
159     JMenuItem                   _move_node_names_to_seq_names_jmi;
160     JMenuItem                   _extract_tax_code_from_node_names_jmi;
161     JMenuItem                   _annotate_item;
162     // font size menu:
163     JMenuItem                   _super_tiny_fonts_item;
164     JMenuItem                   _tiny_fonts_item;
165     JMenuItem                   _small_fonts_item;
166     JMenuItem                   _medium_fonts_item;
167     JMenuItem                   _large_fonts_item;
168     // options menu:
169     // _  screen and print
170     JMenuItem                   _choose_font_mi;
171     JMenuItem                   _switch_colors_mi;
172     JCheckBoxMenuItem           _label_direction_cbmi;
173     // _  screen display
174     JCheckBoxMenuItem           _screen_antialias_cbmi;
175     JCheckBoxMenuItem           _background_gradient_cbmi;
176     JRadioButtonMenuItem        _non_lined_up_cladograms_rbmi;
177     JRadioButtonMenuItem        _uniform_cladograms_rbmi;
178     JRadioButtonMenuItem        _ext_node_dependent_cladogram_rbmi;
179     JCheckBoxMenuItem           _show_branch_length_values_cbmi;
180     JCheckBoxMenuItem           _color_by_taxonomic_group_cbmi;
181     
182     JCheckBoxMenuItem           _show_scale_cbmi;                                                                                                                                                                                             //TODO fix me
183     JCheckBoxMenuItem           _show_overview_cbmi;
184     JCheckBoxMenuItem           _show_domain_labels;
185     JCheckBoxMenuItem           _show_annotation_ref_source;
186     JCheckBoxMenuItem           _abbreviate_scientific_names;
187     JCheckBoxMenuItem           _color_labels_same_as_parent_branch;
188     JMenuItem                   _overview_placment_mi;
189     JMenuItem                   _choose_minimal_confidence_mi;
190     JCheckBoxMenuItem           _show_default_node_shapes_internal_cbmi;
191     JCheckBoxMenuItem           _show_default_node_shapes_external_cbmi;
192     JMenuItem                   _cycle_node_shape_mi;
193     JMenuItem                   _cycle_node_fill_mi;
194     JMenuItem                   _choose_node_size_mi;
195     JCheckBoxMenuItem           _taxonomy_colorize_node_shapes_cbmi;
196     JCheckBoxMenuItem           _show_confidence_stddev_cbmi;
197     // _  print
198     JCheckBoxMenuItem           _graphics_export_visible_only_cbmi;
199     JCheckBoxMenuItem           _antialias_print_cbmi;
200     JCheckBoxMenuItem           _print_black_and_white_cbmi;
201     JCheckBoxMenuItem           _print_using_actual_size_cbmi;
202     JCheckBoxMenuItem           _graphics_export_using_actual_size_cbmi;
203     JMenuItem                   _print_size_mi;
204     JMenuItem                   _choose_pdf_width_mi;
205     // _  parsing
206     JCheckBoxMenuItem           _internal_number_are_confidence_for_nh_parsing_cbmi;
207     JRadioButtonMenuItem        _extract_taxonomy_no_rbmi;
208     JRadioButtonMenuItem        _extract_taxonomy_agressive_rbmi;
209     JRadioButtonMenuItem        _extract_taxonomy_pfam_strict_rbmi;
210     JRadioButtonMenuItem        _extract_taxonomy_pfam_relaxed_rbmi;
211     JCheckBoxMenuItem           _replace_underscores_cbmi;
212     JCheckBoxMenuItem           _use_brackets_for_conf_in_nh_export_cbmi;
213     JCheckBoxMenuItem           _use_internal_names_for_conf_in_nh_export_cbmi;
214     // _  search
215     JCheckBoxMenuItem           _search_case_senstive_cbmi;
216     JCheckBoxMenuItem           _search_whole_words_only_cbmi;
217     JCheckBoxMenuItem           _inverse_search_result_cbmi;
218     // type menu:
219     JMenu                       _type_menu;
220     JCheckBoxMenuItem           _rectangular_type_cbmi;
221     JCheckBoxMenuItem           _triangular_type_cbmi;
222     JCheckBoxMenuItem           _curved_type_cbmi;
223     JCheckBoxMenuItem           _convex_type_cbmi;
224     JCheckBoxMenuItem           _euro_type_cbmi;
225     JCheckBoxMenuItem           _rounded_type_cbmi;
226     JCheckBoxMenuItem           _unrooted_type_cbmi;
227     JCheckBoxMenuItem           _circular_type_cbmi;
228     // view as text menu:
229     JMenuItem                   _view_as_NH_item;
230     JMenuItem                   _view_as_XML_item;
231     JMenuItem                   _view_as_nexus_item;
232     JMenuItem                   _display_basic_information_item;
233     // help menu:
234     JMenuItem                   _about_item;
235     JMenuItem                   _help_item;
236     JMenuItem                   _website_item;
237     JMenuItem                   _phyloxml_website_item;
238     JMenuItem                   _phyloxml_ref_item;
239     JMenuItem                   _aptx_ref_item;
240     // process menu:
241     JMenu                       _process_menu;
242     // Handy pointers to child components:
243     MainPanel                   _mainpanel;
244     Container                   _contentpane;
245     final LinkedList<TextFrame> _textframes                             = new LinkedList<TextFrame>();                                                                                                                                         ;
246     Configuration               _configuration;
247     JMenuItem                   _remove_branch_color_item;
248     Options                     _options;
249     private Phylogeny           _species_tree;
250     InferenceManager            _inference_manager;
251     final ProcessPool           _process_pool;
252     private String              _previous_node_annotation_ref;
253
254     MainFrame() {
255         _process_pool = ProcessPool.createInstance();
256     }
257
258     /**
259      * Action performed.
260      */
261     @Override
262     public void actionPerformed( final ActionEvent e ) {
263         final Object o = e.getSource();
264         boolean is_applet = false;
265         JApplet applet = null;
266         if ( getCurrentTreePanel() != null ) {
267             is_applet = getCurrentTreePanel().isApplet();
268             if ( is_applet ) {
269                 applet = getCurrentTreePanel().obtainApplet();
270             }
271         }
272         if ( o == _open_url_item ) {
273             readPhylogeniesFromURL();
274         }
275         else if ( o == _exit_item ) {
276             close();
277         }
278         else if ( o == _gsdi_item ) {
279             if ( isSubtreeDisplayed() ) {
280                 return;
281             }
282             executeGSDI();
283         }
284         else if ( o == _gsdir_item ) {
285             if ( isSubtreeDisplayed() ) {
286                 return;
287             }
288             executeGSDIR();
289         }
290         else if ( o == _taxcolor_item ) {
291             taxColor();
292         }
293         else if ( o == _confcolor_item ) {
294             confColor();
295         }
296         else if ( o == _color_rank_jmi ) {
297             colorRank();
298         }
299         else if ( o == _collapse_species_specific_subtrees ) {
300             if ( isSubtreeDisplayed() ) {
301                 return;
302             }
303             if ( getCurrentTreePanel() != null ) {
304                 getCurrentTreePanel().collapseSpeciesSpecificSubtrees();
305             }
306         }
307         else if ( o == _remove_branch_color_item ) {
308             if ( isSubtreeDisplayed() ) {
309                 return;
310             }
311             removeBranchColors();
312         }
313         else if ( o == _midpoint_root_item ) {
314             if ( isSubtreeDisplayed() ) {
315                 return;
316             }
317             midpointRoot();
318         }
319         else if ( o == _annotate_item ) {
320             annotateSequences();
321         }
322         else if ( o == _switch_colors_mi ) {
323             switchColors();
324         }
325         else if ( o == _display_basic_information_item ) {
326             displayBasicInformation();
327         }
328         else if ( o == _view_as_NH_item ) {
329             viewAsNH();
330         }
331         else if ( o == _view_as_XML_item ) {
332             viewAsXML();
333         }
334         else if ( o == _view_as_nexus_item ) {
335             viewAsNexus();
336         }
337         else if ( o == _super_tiny_fonts_item ) {
338             if ( getCurrentTreePanel() != null ) {
339                 getCurrentTreePanel().setSuperTinyFonts();
340                 getCurrentTreePanel().repaint();
341             }
342         }
343         else if ( o == _tiny_fonts_item ) {
344             if ( getCurrentTreePanel() != null ) {
345                 getCurrentTreePanel().setTinyFonts();
346                 getCurrentTreePanel().repaint();
347             }
348         }
349         else if ( o == _small_fonts_item ) {
350             if ( getCurrentTreePanel() != null ) {
351                 getCurrentTreePanel().setSmallFonts();
352                 getCurrentTreePanel().repaint();
353             }
354         }
355         else if ( o == _medium_fonts_item ) {
356             if ( getCurrentTreePanel() != null ) {
357                 getCurrentTreePanel().setMediumFonts();
358                 getCurrentTreePanel().repaint();
359             }
360         }
361         else if ( o == _large_fonts_item ) {
362             if ( getCurrentTreePanel() != null ) {
363                 getCurrentTreePanel().setLargeFonts();
364                 getCurrentTreePanel().repaint();
365             }
366         }
367         else if ( o == _choose_font_mi ) {
368             chooseFont();
369         }
370         else if ( o == _choose_minimal_confidence_mi ) {
371             chooseMinimalConfidence();
372         }
373         else if ( o == _choose_node_size_mi ) {
374             chooseNodeSize( getOptions(), this );
375         }
376         else if ( o == _overview_placment_mi ) {
377             MainFrame.cycleOverview( getOptions(), getCurrentTreePanel() );
378         }
379         else if ( o == _cycle_node_fill_mi ) {
380             MainFrame.cycleNodeFill( getOptions(), getCurrentTreePanel() );
381         }
382         else if ( o == _cycle_node_shape_mi ) {
383             MainFrame.cycleNodeShape( getOptions(), getCurrentTreePanel() );
384         }
385         else if ( o == _screen_antialias_cbmi ) {
386             updateOptions( getOptions() );
387             updateScreenTextAntialias( getMainPanel().getTreePanels() );
388         }
389         else if ( o == _background_gradient_cbmi ) {
390             updateOptions( getOptions() );
391         }
392         else if ( o == _show_domain_labels ) {
393             updateOptions( getOptions() );
394         }
395         else if ( o == _show_annotation_ref_source ) {
396             updateOptions( getOptions() );
397         }
398         else if ( o == _abbreviate_scientific_names ) {
399             updateOptions( getOptions() );
400         }
401         else if ( o == _color_labels_same_as_parent_branch ) {
402             updateOptions( getOptions() );
403         }
404         else if ( o == _show_default_node_shapes_internal_cbmi ) {
405             updateOptions( getOptions() );
406         }
407         else if ( o == _show_default_node_shapes_external_cbmi ) {
408             updateOptions( getOptions() );
409         }
410         else if ( o == _taxonomy_colorize_node_shapes_cbmi ) {
411             updateOptions( getOptions() );
412         }
413         else if ( o == _non_lined_up_cladograms_rbmi ) {
414             updateOptions( getOptions() );
415             showWhole();
416         }
417         else if ( o == _uniform_cladograms_rbmi ) {
418             updateOptions( getOptions() );
419             showWhole();
420         }
421         else if ( o == _ext_node_dependent_cladogram_rbmi ) {
422             updateOptions( getOptions() );
423             showWhole();
424         }
425         else if ( o == _search_case_senstive_cbmi ) {
426             updateOptions( getOptions() );
427             getMainPanel().getControlPanel().search();
428         }
429         else if ( o == _search_whole_words_only_cbmi ) {
430             updateOptions( getOptions() );
431             getMainPanel().getControlPanel().search();
432         }
433         else if ( o == _inverse_search_result_cbmi ) {
434             updateOptions( getOptions() );
435             getMainPanel().getControlPanel().search();
436         }
437         else if ( o == _show_scale_cbmi ) {
438             updateOptions( getOptions() );
439         }
440         else if ( o == _show_branch_length_values_cbmi ) {
441             updateOptions( getOptions() );
442         }
443         else if ( o == _color_by_taxonomic_group_cbmi ) {
444             updateOptions( getOptions() );
445         }
446         
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( "View as phyloXML" ) );
670         _view_jmenu.add( _view_as_NH_item = new JMenuItem( "View as Newick" ) );
671         _view_jmenu.add( _view_as_nexus_item = new JMenuItem( "View 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() {
767         if ( ( _mainpanel.getCurrentPhylogeny() != null ) && !_mainpanel.getCurrentPhylogeny().isEmpty() ) {
768             String title = "Basic Information";
769             if ( !ForesterUtil.isEmpty( _mainpanel.getCurrentPhylogeny().getName() ) ) {
770                 title = _mainpanel.getCurrentPhylogeny().getName() + " " + title;
771             }
772             showTextFrame( AptxUtil.createBasicInformation( _mainpanel.getCurrentPhylogeny() ), 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         options.setTaxonomyColorizeNodeShapes( ( _taxonomy_colorize_node_shapes_cbmi != null )
1285                 && _taxonomy_colorize_node_shapes_cbmi.isSelected() );
1286         if ( ( _non_lined_up_cladograms_rbmi != null ) && ( _non_lined_up_cladograms_rbmi.isSelected() ) ) {
1287             options.setCladogramType( CLADOGRAM_TYPE.NON_LINED_UP );
1288         }
1289         else if ( ( _uniform_cladograms_rbmi != null ) && ( _uniform_cladograms_rbmi.isSelected() ) ) {
1290             options.setCladogramType( CLADOGRAM_TYPE.TOTAL_NODE_SUM_DEP );
1291         }
1292         else if ( ( _ext_node_dependent_cladogram_rbmi != null ) && ( _ext_node_dependent_cladogram_rbmi.isSelected() ) ) {
1293             options.setCladogramType( CLADOGRAM_TYPE.EXT_NODE_SUM_DEP );
1294         }
1295         options.setSearchCaseSensitive( ( _search_case_senstive_cbmi != null )
1296                 && _search_case_senstive_cbmi.isSelected() );
1297         if ( ( _show_scale_cbmi != null ) && _show_scale_cbmi.isEnabled() ) {
1298             options.setShowScale( _show_scale_cbmi.isSelected() );
1299         }
1300         if ( _label_direction_cbmi != null ) {
1301             if ( _label_direction_cbmi.isSelected() ) {
1302                 options.setNodeLabelDirection( NODE_LABEL_DIRECTION.RADIAL );
1303             }
1304             else {
1305                 options.setNodeLabelDirection( NODE_LABEL_DIRECTION.HORIZONTAL );
1306             }
1307         }
1308         options.setShowOverview( ( _show_overview_cbmi != null ) && _show_overview_cbmi.isSelected() );
1309         options.setShowConfidenceStddev( ( _show_confidence_stddev_cbmi != null )
1310                 && _show_confidence_stddev_cbmi.isSelected() );
1311         if ( ( _show_branch_length_values_cbmi != null ) && _show_branch_length_values_cbmi.isEnabled() ) {
1312             options.setShowBranchLengthValues( _show_branch_length_values_cbmi.isSelected() );
1313         }
1314         
1315         if ( ( _color_by_taxonomic_group_cbmi != null ) &&  _color_by_taxonomic_group_cbmi.isEnabled() ) {
1316             options.setColorByTaxonomicGroup(  _color_by_taxonomic_group_cbmi.isSelected() );
1317         }
1318         
1319         
1320         options.setPrintUsingActualSize( ( _print_using_actual_size_cbmi != null )
1321                 && ( _print_using_actual_size_cbmi.isSelected() ) );
1322         options.setGraphicsExportUsingActualSize( ( _graphics_export_using_actual_size_cbmi != null )
1323                 && ( _graphics_export_using_actual_size_cbmi.isSelected() ) );
1324         options.setAntialiasPrint( ( _antialias_print_cbmi != null ) && _antialias_print_cbmi.isSelected() );
1325         if ( ( _use_brackets_for_conf_in_nh_export_cbmi != null )
1326                 && _use_brackets_for_conf_in_nh_export_cbmi.isSelected() ) {
1327             options.setNhConversionSupportValueStyle( NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS );
1328         }
1329         else if ( ( _use_internal_names_for_conf_in_nh_export_cbmi != null )
1330                 && _use_internal_names_for_conf_in_nh_export_cbmi.isSelected() ) {
1331             options.setNhConversionSupportValueStyle( NH_CONVERSION_SUPPORT_VALUE_STYLE.AS_INTERNAL_NODE_NAMES );
1332         }
1333         else {
1334             options.setNhConversionSupportValueStyle( NH_CONVERSION_SUPPORT_VALUE_STYLE.NONE );
1335         }
1336         options.setPrintBlackAndWhite( ( _print_black_and_white_cbmi != null )
1337                 && _print_black_and_white_cbmi.isSelected() );
1338         options.setInternalNumberAreConfidenceForNhParsing( ( _internal_number_are_confidence_for_nh_parsing_cbmi != null )
1339                 && _internal_number_are_confidence_for_nh_parsing_cbmi.isSelected() );
1340         if ( ( _extract_taxonomy_pfam_strict_rbmi != null ) && _extract_taxonomy_pfam_strict_rbmi.isSelected() ) {
1341             options.setTaxonomyExtraction( TAXONOMY_EXTRACTION.PFAM_STYLE_STRICT );
1342         }
1343         else if ( ( _extract_taxonomy_pfam_relaxed_rbmi != null ) && _extract_taxonomy_pfam_relaxed_rbmi.isSelected() ) {
1344             options.setTaxonomyExtraction( TAXONOMY_EXTRACTION.PFAM_STYLE_RELAXED );
1345         }
1346         else if ( ( _extract_taxonomy_agressive_rbmi != null ) && _extract_taxonomy_agressive_rbmi.isSelected() ) {
1347             options.setTaxonomyExtraction( TAXONOMY_EXTRACTION.AGGRESSIVE );
1348         }
1349         else if ( ( _extract_taxonomy_no_rbmi != null ) && _extract_taxonomy_no_rbmi.isSelected() ) {
1350             options.setTaxonomyExtraction( TAXONOMY_EXTRACTION.NO );
1351         }
1352         options.setReplaceUnderscoresInNhParsing( ( _replace_underscores_cbmi != null )
1353                 && _replace_underscores_cbmi.isSelected() );
1354         options.setMatchWholeTermsOnly( ( _search_whole_words_only_cbmi != null )
1355                 && _search_whole_words_only_cbmi.isSelected() );
1356         options.setInverseSearchResult( ( _inverse_search_result_cbmi != null )
1357                 && _inverse_search_result_cbmi.isSelected() );
1358         if ( _graphics_export_visible_only_cbmi != null ) {
1359             options.setGraphicsExportVisibleOnly( _graphics_export_visible_only_cbmi.isSelected() );
1360             if ( _graphics_export_visible_only_cbmi.isSelected() && ( _graphics_export_using_actual_size_cbmi != null ) ) {
1361                 _graphics_export_using_actual_size_cbmi.setSelected( true );
1362                 _graphics_export_using_actual_size_cbmi.setEnabled( false );
1363             }
1364             else {
1365                 _graphics_export_using_actual_size_cbmi.setEnabled( true );
1366             }
1367         }
1368         if ( ( _rectangular_type_cbmi != null ) && _rectangular_type_cbmi.isSelected() ) {
1369             options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR );
1370         }
1371         else if ( ( _triangular_type_cbmi != null ) && _triangular_type_cbmi.isSelected() ) {
1372             options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.TRIANGULAR );
1373         }
1374         else if ( ( _curved_type_cbmi != null ) && _curved_type_cbmi.isSelected() ) {
1375             options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CURVED );
1376         }
1377         else if ( ( _convex_type_cbmi != null ) && _convex_type_cbmi.isSelected() ) {
1378             options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CONVEX );
1379         }
1380         else if ( ( _euro_type_cbmi != null ) && _euro_type_cbmi.isSelected() ) {
1381             options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE );
1382         }
1383         else if ( ( _rounded_type_cbmi != null ) && _rounded_type_cbmi.isSelected() ) {
1384             options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.ROUNDED );
1385         }
1386         else if ( ( _unrooted_type_cbmi != null ) && _unrooted_type_cbmi.isSelected() ) {
1387             options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.UNROOTED );
1388         }
1389         else if ( ( _circular_type_cbmi != null ) && _circular_type_cbmi.isSelected() ) {
1390             options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CIRCULAR );
1391         }
1392     }
1393
1394     void updateTypeCheckboxes( final Options options, final Object o ) {
1395         setTypeMenuToAllUnselected();
1396         ( ( JCheckBoxMenuItem ) o ).setSelected( true );
1397     }
1398
1399     void viewAsNexus() {
1400         if ( ( _mainpanel.getCurrentPhylogeny() != null ) && !_mainpanel.getCurrentPhylogeny().isEmpty() ) {
1401             String title = "Nexus";
1402             if ( !ForesterUtil.isEmpty( _mainpanel.getCurrentPhylogeny().getName() ) ) {
1403                 title = _mainpanel.getCurrentPhylogeny().getName() + " " + title;
1404             }
1405             showTextFrame( _mainpanel.getCurrentPhylogeny().toNexus( getOptions().getNhConversionSupportValueStyle() ),
1406                            title );
1407         }
1408     }
1409
1410     void viewAsNH() {
1411         if ( ( _mainpanel.getCurrentPhylogeny() != null ) && !_mainpanel.getCurrentPhylogeny().isEmpty() ) {
1412             String title = "New Hampshire";
1413             if ( !ForesterUtil.isEmpty( _mainpanel.getCurrentPhylogeny().getName() ) ) {
1414                 title = _mainpanel.getCurrentPhylogeny().getName() + " " + title;
1415             }
1416             showTextFrame( _mainpanel.getCurrentPhylogeny()
1417                                    .toNewHampshire( false, getOptions().getNhConversionSupportValueStyle() ),
1418                            title );
1419         }
1420     }
1421
1422     void viewAsXML() {
1423         if ( ( _mainpanel.getCurrentPhylogeny() != null ) && !_mainpanel.getCurrentPhylogeny().isEmpty() ) {
1424             String title = "phyloXML";
1425             if ( !ForesterUtil.isEmpty( _mainpanel.getCurrentPhylogeny().getName() ) ) {
1426                 title = _mainpanel.getCurrentPhylogeny().getName() + " " + title;
1427             }
1428             showTextFrame( _mainpanel.getCurrentPhylogeny().toPhyloXML( 0 ), title );
1429         }
1430     }
1431
1432     private void annotateSequences() {
1433         if ( getCurrentTreePanel() != null ) {
1434             final Set<Long> nodes = getCurrentTreePanel().getFoundNodes();
1435             if ( ( nodes == null ) || nodes.isEmpty() ) {
1436                 JOptionPane
1437                         .showMessageDialog( this,
1438                                             "Need to select nodes, either via direct selection or via the \"Search\" function",
1439                                             "No nodes selected for annotation",
1440                                             JOptionPane.ERROR_MESSAGE );
1441                 return;
1442             }
1443             final Phylogeny phy = getMainPanel().getCurrentPhylogeny();
1444             if ( ( phy != null ) && !phy.isEmpty() ) {
1445                 final JTextField ref_field = new JTextField( 10 );
1446                 final JTextField desc_filed = new JTextField( 20 );
1447                 ref_field.setText( ForesterUtil.isEmpty( getPreviousNodeAnnotationReference() ) ? ""
1448                         : getPreviousNodeAnnotationReference() );
1449                 final JPanel my_panel = new JPanel();
1450                 my_panel.add( new JLabel( "Reference " ) );
1451                 my_panel.add( ref_field );
1452                 my_panel.add( Box.createHorizontalStrut( 15 ) );
1453                 my_panel.add( new JLabel( "Description " ) );
1454                 my_panel.add( desc_filed );
1455                 final int result = JOptionPane.showConfirmDialog( null,
1456                                                                   my_panel,
1457                                                                   "Enter the sequence annotation(s) for the "
1458                                                                           + nodes.size() + " selected nodes",
1459                                                                   JOptionPane.OK_CANCEL_OPTION );
1460                 if ( result == JOptionPane.OK_OPTION ) {
1461                     String ref = ref_field.getText();
1462                     String desc = desc_filed.getText();
1463                     if ( !ForesterUtil.isEmpty( ref ) ) {
1464                         ref = ref.trim();
1465                         ref = ref.replaceAll( "\\s+", " " );
1466                         if ( ( ref.indexOf( ':' ) < 1 ) || ( ref.indexOf( ':' ) > ref.length() - 2 )
1467                                 || ( ref.length() < 3 ) ) {
1468                             JOptionPane.showMessageDialog( this,
1469                                                            "Reference needs to be in the form of \"GO:1234567\"",
1470                                                            "Illegal Format for Annotation Reference",
1471                                                            JOptionPane.ERROR_MESSAGE );
1472                             return;
1473                         }
1474                     }
1475                     if ( ref != null ) {
1476                         setPreviousNodeAnnotationReference( ref );
1477                     }
1478                     if ( desc != null ) {
1479                         desc = desc.trim();
1480                         desc = desc.replaceAll( "\\s+", " " );
1481                     }
1482                     if ( !ForesterUtil.isEmpty( ref ) || !ForesterUtil.isEmpty( desc ) ) {
1483                         for( final Long id : nodes ) {
1484                             final PhylogenyNode n = phy.getNode( id );
1485                             ForesterUtil.ensurePresenceOfSequence( n );
1486                             final Annotation ann = ForesterUtil.isEmpty( ref ) ? new Annotation()
1487                                     : new Annotation( ref );
1488                             if ( !ForesterUtil.isEmpty( desc ) ) {
1489                                 ann.setDesc( desc );
1490                             }
1491                             n.getNodeData().getSequence().addAnnotation( ann );
1492                         }
1493                     }
1494                     getMainPanel().getControlPanel().showAnnotations();
1495                 }
1496             }
1497         }
1498     }
1499
1500     private void chooseFont() {
1501         final FontChooser fc = new FontChooser();
1502         fc.setFont( getMainPanel().getTreeFontSet().getLargeFont() );
1503         fc.showDialog( this, "Select the Base Font" );
1504         getMainPanel().getTreeFontSet().setBaseFont( fc.getFont() );
1505     }
1506
1507     private void chooseMinimalConfidence() {
1508         final String s = ( String ) JOptionPane
1509                 .showInputDialog( this,
1510                                   "Please enter the minimum for confidence values to be displayed.\n"
1511                                           + "[current value: " + getOptions().getMinConfidenceValue() + "]\n",
1512                                   "Minimal Confidence Value",
1513                                   JOptionPane.QUESTION_MESSAGE,
1514                                   null,
1515                                   null,
1516                                   getOptions().getMinConfidenceValue() );
1517         if ( !ForesterUtil.isEmpty( s ) ) {
1518             boolean success = true;
1519             double m = 0.0;
1520             final String m_str = s.trim();
1521             if ( !ForesterUtil.isEmpty( m_str ) ) {
1522                 try {
1523                     m = Double.parseDouble( m_str );
1524                 }
1525                 catch ( final Exception ex ) {
1526                     success = false;
1527                 }
1528             }
1529             else {
1530                 success = false;
1531             }
1532             if ( success && ( m >= 0.0 ) ) {
1533                 getOptions().setMinConfidenceValue( m );
1534             }
1535         }
1536     }
1537
1538     private void doUpdateProcessMenu() {
1539         if ( _process_pool.size() > 0 ) {
1540             if ( _process_menu == null ) {
1541                 _process_menu = createMenu( "", getConfiguration() );
1542                 _process_menu.setForeground( Color.RED );
1543             }
1544             _process_menu.removeAll();
1545             final String text = "processes running: " + _process_pool.size();
1546             _process_menu.setText( text );
1547             _jmenubar.add( _process_menu );
1548             for( int i = 0; i < _process_pool.size(); ++i ) {
1549                 final ProcessRunning p = _process_pool.getProcessByIndex( i );
1550                 _process_menu.add( customizeJMenuItem( new JMenuItem( p.getName() + " [" + p.getStart() + "]" ) ) );
1551             }
1552         }
1553         else {
1554             if ( _process_menu != null ) {
1555                 _process_menu.removeAll();
1556                 _jmenubar.remove( _process_menu );
1557             }
1558         }
1559         _jmenubar.validate();
1560         _jmenubar.repaint();
1561         repaint();
1562     }
1563
1564     private String getPreviousNodeAnnotationReference() {
1565         return _previous_node_annotation_ref;
1566     }
1567
1568     private void removeBranchColors() {
1569         if ( getMainPanel().getCurrentPhylogeny() != null ) {
1570             AptxUtil.removeBranchColors( getMainPanel().getCurrentPhylogeny() );
1571         }
1572     }
1573
1574     private void setPreviousNodeAnnotationReference( final String previous_node_annotation_ref ) {
1575         _previous_node_annotation_ref = previous_node_annotation_ref;
1576     }
1577
1578     /**
1579      * Display the about box.
1580      */
1581     static void about() {
1582         final StringBuffer about = new StringBuffer( "Archaeopteryx\nVersion " + Constants.VERSION + "\n" );
1583         about.append( "Copyright (C) 2013 Christian M. Zmasek\n" );
1584         about.append( "All Rights Reserved\n" );
1585         about.append( "License: GNU Lesser General Public License (LGPL)\n" );
1586         about.append( "Last modified: " + Constants.PRG_DATE + "\n" );
1587         about.append( "Based on: " + ForesterUtil.getForesterLibraryInformation() + "\n" );
1588         about.append( "phyloXML version : " + ForesterConstants.PHYLO_XML_VERSION + "\n" );
1589         about.append( "phyloXML location: " + ForesterConstants.PHYLO_XML_LOCATION + "\n" );
1590         if ( !ForesterUtil.isEmpty( ForesterUtil.JAVA_VERSION ) && !ForesterUtil.isEmpty( ForesterUtil.JAVA_VENDOR ) ) {
1591             about.append( "[your Java version: " + ForesterUtil.JAVA_VERSION + " " + ForesterUtil.JAVA_VENDOR + "]\n" );
1592         }
1593         if ( !ForesterUtil.isEmpty( ForesterUtil.OS_NAME ) && !ForesterUtil.isEmpty( ForesterUtil.OS_ARCH )
1594                 && !ForesterUtil.isEmpty( ForesterUtil.OS_VERSION ) ) {
1595             about.append( "[your OS: " + ForesterUtil.OS_NAME + " " + ForesterUtil.OS_ARCH + " "
1596                     + ForesterUtil.OS_VERSION + "]\n" );
1597         }
1598         final Runtime rt = java.lang.Runtime.getRuntime();
1599         final long free_memory = rt.freeMemory() / 1000000;
1600         final long total_memory = rt.totalMemory() / 1000000;
1601         about.append( "[free memory: " + free_memory + "MB, total memory: " + total_memory + "MB]\n" );
1602         about.append( "[locale: " + Locale.getDefault() + "]\n" );
1603         about.append( "References:\n" );
1604         about.append( Constants.PHYLOXML_REFERENCE_SHORT + "\n" );
1605         about.append( "For more information & download:\n" );
1606         about.append( Constants.APTX_WEB_SITE + "\n" );
1607         about.append( "Comments: " + Constants.AUTHOR_EMAIL );
1608         JOptionPane.showMessageDialog( null, about, Constants.PRG_NAME, JOptionPane.PLAIN_MESSAGE );
1609     }
1610
1611     static void chooseNodeSize( final Options options, final Component parent ) {
1612         final String s = ( String ) JOptionPane.showInputDialog( parent,
1613                                                                  "Please enter the default size for node shapes.\n"
1614                                                                          + "[current value: "
1615                                                                          + options.getDefaultNodeShapeSize() + "]\n",
1616                                                                  "Node Shape Size",
1617                                                                  JOptionPane.QUESTION_MESSAGE,
1618                                                                  null,
1619                                                                  null,
1620                                                                  options.getDefaultNodeShapeSize() );
1621         if ( !ForesterUtil.isEmpty( s ) ) {
1622             boolean success = true;
1623             double m = 0.0;
1624             final String m_str = s.trim();
1625             if ( !ForesterUtil.isEmpty( m_str ) ) {
1626                 try {
1627                     m = Double.parseDouble( m_str );
1628                 }
1629                 catch ( final Exception ex ) {
1630                     success = false;
1631                 }
1632             }
1633             else {
1634                 success = false;
1635             }
1636             if ( success && ( m >= 0.0 ) ) {
1637                 final short size = ForesterUtil.roundToShort( m );
1638                 if ( size >= 0.0 ) {
1639                     options.setDefaultNodeShapeSize( size );
1640                 }
1641             }
1642         }
1643     }
1644
1645     static String createCurrentFontDesc( final TreeFontSet tree_font_set ) {
1646         return tree_font_set.getLargeFont().getFamily() + " " + tree_font_set.getLargeFont().getSize();
1647     }
1648
1649     static JMenu createMenu( final String title, final Configuration conf ) {
1650         final JMenu jmenu = new JMenu( title );
1651         if ( !conf.isUseNativeUI() ) {
1652             jmenu.setFont( MainFrame.menu_font );
1653             jmenu.setBackground( conf.getGuiMenuBackgroundColor() );
1654             jmenu.setForeground( conf.getGuiMenuTextColor() );
1655         }
1656         return jmenu;
1657     }
1658
1659     static JMenuItem customizeMenuItemAsLabel( final JMenuItem label, final Configuration configuration ) {
1660         label.setFont( MainFrame.menu_font.deriveFont( Font.BOLD ) );
1661         if ( !configuration.isUseNativeUI() ) {
1662             label.setBackground( configuration.getGuiMenuBackgroundColor() );
1663             label.setForeground( configuration.getGuiMenuTextColor() );
1664             label.setOpaque( true );
1665         }
1666         label.setSelected( false );
1667         label.setEnabled( false );
1668         return label;
1669     }
1670
1671     static void cycleNodeFill( final Options op, final TreePanel tree_panel ) {
1672         switch ( op.getDefaultNodeFill() ) {
1673             case GRADIENT:
1674                 op.setDefaultNodeFill( NodeFill.SOLID );
1675                 break;
1676             case NONE:
1677                 op.setDefaultNodeFill( NodeFill.GRADIENT );
1678                 break;
1679             case SOLID:
1680                 op.setDefaultNodeFill( NodeFill.NONE );
1681                 break;
1682             default:
1683                 throw new RuntimeException( "unknown fill: " + op.getDefaultNodeFill() );
1684         }
1685     }
1686
1687     static void cycleNodeShape( final Options op, final TreePanel tree_panel ) {
1688         switch ( op.getDefaultNodeShape() ) {
1689             case CIRCLE:
1690                 op.setDefaultNodeShape( NodeShape.RECTANGLE );
1691                 break;
1692             case RECTANGLE:
1693                 op.setDefaultNodeShape( NodeShape.CIRCLE );
1694                 break;
1695             default:
1696                 throw new RuntimeException( "unknown shape: " + op.getDefaultNodeShape() );
1697         }
1698     }
1699
1700     static void cycleOverview( final Options op, final TreePanel tree_panel ) {
1701         switch ( op.getOvPlacement() ) {
1702             case LOWER_LEFT:
1703                 op.setOvPlacement( Options.OVERVIEW_PLACEMENT_TYPE.UPPER_LEFT );
1704                 break;
1705             case LOWER_RIGHT:
1706                 op.setOvPlacement( Options.OVERVIEW_PLACEMENT_TYPE.LOWER_LEFT );
1707                 break;
1708             case UPPER_LEFT:
1709                 op.setOvPlacement( Options.OVERVIEW_PLACEMENT_TYPE.UPPER_RIGHT );
1710                 break;
1711             case UPPER_RIGHT:
1712                 op.setOvPlacement( Options.OVERVIEW_PLACEMENT_TYPE.LOWER_RIGHT );
1713                 break;
1714             default:
1715                 throw new RuntimeException( "unknown placement: " + op.getOvPlacement() );
1716         }
1717         if ( tree_panel != null ) {
1718             tree_panel.updateOvSettings();
1719         }
1720     }
1721
1722     static void setCycleNodeFillMenuItem( final JMenuItem mi, final Options options ) {
1723         if ( ( options != null ) && ( options.getDefaultNodeFill() != null ) ) {
1724             mi.setText( "Cycle Node Shape Fill Type... (current: "
1725                     + options.getDefaultNodeFill().toString().toLowerCase() + ")" );
1726         }
1727         else {
1728             mi.setText( "Cycle Node Shape Fill Type..." );
1729         }
1730     }
1731
1732     static void setCycleNodeShapeMenuItem( final JMenuItem mi, final Options options ) {
1733         if ( ( options != null ) && ( options.getDefaultNodeShape() != null ) ) {
1734             mi.setText( "Cycle Node Shape Fill Type... (current: "
1735                     + options.getDefaultNodeShape().toString().toLowerCase() + ")" );
1736         }
1737         else {
1738             mi.setText( "Cycle Node Shape Fill Type..." );
1739         }
1740     }
1741
1742     static void setOvPlacementColorChooseMenuItem( final JMenuItem mi, final Options options ) {
1743         if ( ( options != null ) && ( options.getOvPlacement() != null ) ) {
1744             mi.setText( "Cycle Overview Placement... (current: " + options.getOvPlacement() + ")" );
1745         }
1746         else {
1747             mi.setText( "Cycle Overview Placement..." );
1748         }
1749     }
1750
1751     static void setTextColorChooseMenuItem( final JMenuItem mi, final TreePanel tree_panel ) {
1752         if ( ( tree_panel != null ) && ( tree_panel.getTreeColorSet() != null ) ) {
1753             mi.setText( "Select Colors... (current: " + tree_panel.getTreeColorSet().getCurrentColorSchemeName() + ")" );
1754         }
1755         else {
1756             mi.setText( "Select Colors..." );
1757         }
1758     }
1759
1760     static void setTextForFontChooserMenuItem( final JMenuItem mi, final String font_desc ) {
1761         mi.setText( "Select Font... (current: " + font_desc + ")" );
1762     }
1763
1764     static void setTextMinSupportMenuItem( final JMenuItem mi, final Options options, final TreePanel current_tree_panel ) {
1765         if ( ( current_tree_panel == null ) || ( current_tree_panel.getPhylogeny() == null ) ) {
1766             mi.setEnabled( true );
1767         }
1768         else if ( AptxUtil.isHasAtLeastOneBranchWithSupportValues( current_tree_panel.getPhylogeny() ) ) {
1769             mi.setEnabled( true );
1770         }
1771         else {
1772             mi.setEnabled( false );
1773         }
1774         mi.setText( "Enter Min Confidence Value... (current: " + options.getMinConfidenceValue() + ")" );
1775     }
1776
1777     static void setTextNodeSizeMenuItem( final JMenuItem mi, final Options options ) {
1778         mi.setText( "Enter Default Node Shape Size... (current: " + options.getDefaultNodeShapeSize() + ")" );
1779     }
1780
1781     static void updateOptionsMenuDependingOnPhylogenyType( final MainPanel main_panel,
1782                                                            final JCheckBoxMenuItem scale,
1783                                                            final JCheckBoxMenuItem branch_lengths,
1784                                                            final JRadioButtonMenuItem non_lined_up,
1785                                                            final JRadioButtonMenuItem uniform_clado,
1786                                                            final JRadioButtonMenuItem nonuniform_clado,
1787                                                            final JCheckBoxMenuItem label_direction_cbmi ) {
1788         final TreePanel tree_panel = main_panel.getCurrentTreePanel();
1789         final ControlPanel control = main_panel.getControlPanel();
1790         final Options options = main_panel.getOptions();
1791         scale.setSelected( options.isShowScale() );
1792         branch_lengths.setSelected( options.isShowBranchLengthValues() );
1793         // non_lined_up.setSelected( options.isNonLinedUpCladogram() );
1794         if ( ( tree_panel != null ) && ( !tree_panel.isPhyHasBranchLengths() ) ) {
1795             scale.setSelected( false );
1796             scale.setEnabled( false );
1797             branch_lengths.setSelected( false );
1798             branch_lengths.setEnabled( false );
1799         }
1800         else if ( ( tree_panel != null ) && !control.isDrawPhylogram() ) {
1801             scale.setSelected( false );
1802             scale.setEnabled( false );
1803             branch_lengths.setEnabled( true );
1804         }
1805         else {
1806             scale.setEnabled( true );
1807             branch_lengths.setEnabled( true );
1808         }
1809         if ( ( tree_panel != null )
1810                 && ( ( tree_panel.getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.ROUNDED )
1811                         && ( tree_panel.getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE ) && ( tree_panel
1812                         .getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR ) ) ) {
1813             branch_lengths.setSelected( false );
1814             branch_lengths.setEnabled( false );
1815         }
1816         if ( tree_panel != null ) {
1817             if ( ( tree_panel.getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR )
1818                     || ( tree_panel.getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) ) {
1819                 non_lined_up.setEnabled( false );
1820                 uniform_clado.setEnabled( false );
1821                 nonuniform_clado.setEnabled( false );
1822             }
1823             else {
1824                 non_lined_up.setEnabled( true );
1825                 uniform_clado.setEnabled( true );
1826                 nonuniform_clado.setEnabled( true );
1827             }
1828         }
1829         else {
1830             if ( ( tree_panel != null )
1831                     && ( ( tree_panel.getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE ) && ( tree_panel
1832                             .getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR ) ) ) {
1833                 branch_lengths.setSelected( false );
1834                 branch_lengths.setEnabled( false );
1835             }
1836             if ( ( tree_panel != null )
1837                     && ( ( tree_panel.getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) || ( tree_panel
1838                             .getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) ) ) {
1839                 non_lined_up.setEnabled( false );
1840             }
1841             else {
1842                 // non_lined_up.setSelected( options.isNonLinedUpCladogram() );
1843                 non_lined_up.setEnabled( true );
1844             }
1845         }
1846         label_direction_cbmi.setEnabled( true );
1847         if ( tree_panel != null ) {
1848             if ( ( tree_panel.getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.UNROOTED )
1849                     && ( tree_panel.getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) ) {
1850                 label_direction_cbmi.setEnabled( false );
1851             }
1852             if ( tree_panel.getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) {
1853                 scale.setSelected( false );
1854                 scale.setEnabled( false );
1855             }
1856         }
1857     }
1858
1859     static void updateScreenTextAntialias( final List<TreePanel> treepanels ) {
1860         for( final TreePanel tree_panel : treepanels ) {
1861             tree_panel.setTextAntialias();
1862         }
1863     }
1864 }