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