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