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