in progress
[jalview.git] / forester / java / src / org / forester / archaeopteryx / MainFrame.java
1 // $Id:
2 // FORESTER -- software libraries and applications
3 // for evolutionary biology research and applications.
4 //
5 // Copyright (C) 2008-2010 Christian M. Zmasek
6 // All rights reserved
7 //
8 // This library is free software; you can redistribute it and/or
9 // modify it under the terms of the GNU Lesser General Public
10 // License as published by the Free Software Foundation; either
11 // version 2.1 of the License, or (at your option) any later version.
12 //
13 // This library is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 // Lesser General Public License for more details.
17 //
18 // You should have received a copy of the GNU Lesser General Public
19 // License along with this library; if not, write to the Free Software
20 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
21 //
22 // Contact: phylosoft @ gmail . com
23 // WWW: www.phylosoft.org/forester
24
25 package org.forester.archaeopteryx;
26
27 import java.awt.Component;
28 import java.awt.Container;
29 import java.awt.Font;
30 import java.awt.event.ActionEvent;
31 import java.awt.event.ActionListener;
32 import java.io.IOException;
33 import java.util.List;
34 import java.util.Locale;
35 import java.util.Map;
36
37 import javax.swing.JApplet;
38 import javax.swing.JCheckBoxMenuItem;
39 import javax.swing.JFrame;
40 import javax.swing.JMenu;
41 import javax.swing.JMenuBar;
42 import javax.swing.JMenuItem;
43 import javax.swing.JOptionPane;
44 import javax.swing.JRadioButtonMenuItem;
45
46 import org.forester.archaeopteryx.Options.CLADOGRAM_TYPE;
47 import org.forester.archaeopteryx.Options.NODE_LABEL_DIRECTION;
48 import org.forester.archaeopteryx.Options.PHYLOGENY_GRAPHICS_TYPE;
49 import org.forester.phylogeny.Phylogeny;
50 import org.forester.phylogeny.PhylogenyNodeI.NH_CONVERSION_SUPPORT_VALUE_STYLE;
51 import org.forester.phylogeny.data.NodeVisualization.NodeFill;
52 import org.forester.phylogeny.data.NodeVisualization.NodeShape;
53 import org.forester.util.ForesterConstants;
54 import org.forester.util.ForesterUtil;
55
56 public abstract class MainFrame extends JFrame implements ActionListener {
57
58     static final String       USE_MOUSEWHEEL_SHIFT_TO_ROTATE          = "In this display type, use mousewheel + Shift to rotate [or A and S]";
59     static final String       PHYLOXML_REF_TOOL_TIP                   = Constants.PHYLOXML_REFERENCE;                                                                                                                                       //TODO //FIXME
60     static final String       APTX_REF_TOOL_TIP                       = Constants.APTX_REFERENCE;
61     private static final long serialVersionUID                        = 3655000897845508358L;
62     final static Font         menu_font                               = new Font( Configuration.getDefaultFontFamilyName(),
63                                                                                   Font.PLAIN,
64                                                                                   10 );
65     static final String       TYPE_MENU_HEADER                        = "Type";
66     static final String       RECTANGULAR_TYPE_CBMI_LABEL             = "Rectangular";
67     static final String       EURO_TYPE_CBMI_LABEL                    = "Euro Type";
68     static final String       CURVED_TYPE_CBMI_LABEL                  = "Curved";
69     static final String       TRIANGULAR_TYPE_CBMI_LABEL              = "Triangular";
70     static final String       CONVEX_TYPE_CBMI_LABEL                  = "Convex";
71     static final String       ROUNDED_TYPE_CBMI_LABEL                 = "Rounded";
72     static final String       UNROOTED_TYPE_CBMI_LABEL                = "Unrooted (alpha)";                                                                                                                                                 //TODO
73     static final String       CIRCULAR_TYPE_CBMI_LABEL                = "Circular (alpha)";                                                                                                                                                 //TODO
74     static final String       OPTIONS_HEADER                          = "Options";
75     static final String       SEARCH_SUBHEADER                        = "Search:";
76     static final String       DISPLAY_SUBHEADER                       = "Display:";
77     static final String       SEARCH_TERMS_ONLY_LABEL                 = "Match Complete Terms Only";
78     static final String       SEARCH_CASE_SENSITIVE_LABEL             = "Case Sensitive";
79     static final String       INVERSE_SEARCH_RESULT_LABEL             = "Negate Result";
80     static final String       DISPLAY_BRANCH_LENGTH_VALUES_LABEL      = "Display Branch Length Values";
81     static final String       DISPLAY_SCALE_LABEL                     = "Display Scale";
82     static final String       NON_LINED_UP_CLADOGRAMS_LABEL           = "Non-Lined Up Cladograms";
83     static final String       UNIFORM_CLADOGRAMS_LABEL                = "Total Node Sum Dependent Cladograms";
84     static final String       LABEL_DIRECTION_LABEL                   = "Radial Labels";
85     static final String       LABEL_DIRECTION_TIP                     = "To use radial node labels in radial and unrooted display types";
86     static final String       SCREEN_ANTIALIAS_LABEL                  = "Antialias";
87     static final String       COLOR_LABELS_LABEL                      = "Colorize Labels Same as Parent Branch";
88     static final String       BG_GRAD_LABEL                           = "Background Color Gradient";
89     static final String       DISPLAY_NODE_BOXES_LABEL                = "Show Node Shapes";
90     static final String       SHOW_OVERVIEW_LABEL                     = "Show Overview";
91     static final String       FONT_SIZE_MENU_LABEL                    = "Font Size";
92     static final String       NONUNIFORM_CLADOGRAMS_LABEL             = "External Node Sum Dependent Cladograms";
93     static final String       SHOW_DOMAIN_LABELS_LABEL                = "Show Domain Labels";
94     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";
95     static final String       ABBREV_SN_LABEL                         = "Abbreviate Scientific Taxonomic Names";
96     static final String       TAXONOMY_COLORIZE_NODE_SHAPES_LABEL     = "Colorize Node Shapes According to Taxonomy";
97     static final String       CYCLE_NODE_SHAPE_LABEL                  = "Cycle Node Shapes";
98     static final String       CYCLE_NODE_FILL_LABEL                   = "Cycle Node Fill Type";
99     static final String       CHOOSE_NODE_SIZE_LABEL                  = "Choose Node Shape Size";
100     static final String       SHOW_CONF_STDDEV_LABEL                  = "Show Confidence Standard Deviations";
101     static final String       USE_BRACKETS_FOR_CONF_IN_NH_LABEL       = "Use Brackets for Confidence Values";
102     static final String       USE_INTERNAL_NAMES_FOR_CONF_IN_NH_LABEL = "Use Internal Node Names for Confidence Values";
103     JMenuBar                  _jmenubar;
104     JMenu                     _file_jmenu;
105     JMenu                     _tools_menu;
106     JMenu                     _view_jmenu;
107     JMenu                     _options_jmenu;
108     JMenu                     _font_size_menu;
109     JMenu                     _help_jmenu;
110     JMenuItem[]               _load_phylogeny_from_webservice_menu_items;
111     // file menu:
112     JMenuItem                 _open_item;
113     JMenuItem                 _open_url_item;
114     JMenuItem                 _save_item;
115     JMenuItem                 _save_all_item;
116     JMenuItem                 _close_item;
117     JMenuItem                 _exit_item;
118     JMenuItem                 _new_item;
119     // tools menu:
120     JMenuItem                 _midpoint_root_item;
121     JMenuItem                 _taxcolor_item;
122     JMenuItem                 _confcolor_item;
123     JMenuItem                 _color_rank_jmi;
124     JMenuItem                 _infer_common_sn_names_item;
125     JMenuItem                 _collapse_species_specific_subtrees;
126     JMenuItem                 _collapse_below_threshold;                                                                                                                                                                                    //TODO implememt me
127     JMenuItem                 _obtain_detailed_taxonomic_information_jmi;
128     JMenuItem                 _obtain_detailed_taxonomic_information_deleting_jmi;
129     JMenuItem                 _obtain_uniprot_seq_information_jmi;
130     JMenuItem                 _move_node_names_to_tax_sn_jmi;
131     JMenuItem                 _move_node_names_to_seq_names_jmi;
132     JMenuItem                 _extract_tax_code_from_node_names_jmi;
133     // font size menu:
134     JMenuItem                 _super_tiny_fonts_item;
135     JMenuItem                 _tiny_fonts_item;
136     JMenuItem                 _small_fonts_item;
137     JMenuItem                 _medium_fonts_item;
138     JMenuItem                 _large_fonts_item;
139     // options menu:
140     // _  screen and print
141     JMenuItem                 _choose_font_mi;
142     JMenuItem                 _switch_colors_mi;
143     JCheckBoxMenuItem         _label_direction_cbmi;
144     // _  screen display
145     JCheckBoxMenuItem         _screen_antialias_cbmi;
146     JCheckBoxMenuItem         _background_gradient_cbmi;
147     JRadioButtonMenuItem      _non_lined_up_cladograms_rbmi;
148     JRadioButtonMenuItem      _uniform_cladograms_rbmi;
149     JRadioButtonMenuItem      _ext_node_dependent_cladogram_rbmi;
150     JCheckBoxMenuItem         _show_branch_length_values_cbmi;
151     JCheckBoxMenuItem         _show_scale_cbmi;                                                                                                                                                                                             //TODO fix me
152     JCheckBoxMenuItem         _show_overview_cbmi;
153     JCheckBoxMenuItem         _show_domain_labels;
154     JCheckBoxMenuItem         _abbreviate_scientific_names;
155     JCheckBoxMenuItem         _color_labels_same_as_parent_branch;
156     JMenuItem                 _overview_placment_mi;
157     JMenuItem                 _choose_minimal_confidence_mi;
158     JCheckBoxMenuItem         _show_default_node_shapes_cbmi;
159     JMenuItem                 _cycle_node_shape_mi;
160     JMenuItem                 _cycle_node_fill_mi;
161     JMenuItem                 _choose_node_size_mi;
162     JCheckBoxMenuItem         _taxonomy_colorize_node_shapes_cbmi;
163     JCheckBoxMenuItem         _show_confidence_stddev_cbmi;
164     // _  print
165     JCheckBoxMenuItem         _graphics_export_visible_only_cbmi;
166     JCheckBoxMenuItem         _antialias_print_cbmi;
167     JCheckBoxMenuItem         _print_black_and_white_cbmi;
168     JCheckBoxMenuItem         _print_using_actual_size_cbmi;
169     JCheckBoxMenuItem         _graphics_export_using_actual_size_cbmi;
170     JMenuItem                 _print_size_mi;
171     JMenuItem                 _choose_pdf_width_mi;
172     // _  parsing
173     JCheckBoxMenuItem         _internal_number_are_confidence_for_nh_parsing_cbmi;
174     JCheckBoxMenuItem         _extract_pfam_style_tax_codes_cbmi;
175     JCheckBoxMenuItem         _replace_underscores_cbmi;
176     JCheckBoxMenuItem         _use_brackets_for_conf_in_nh_export_cbmi;
177     JCheckBoxMenuItem         _use_internal_names_for_conf_in_nh_export_cbmi;
178     // _  search
179     JCheckBoxMenuItem         _search_case_senstive_cbmi;
180     JCheckBoxMenuItem         _search_whole_words_only_cbmi;
181     JCheckBoxMenuItem         _inverse_search_result_cbmi;
182     // type menu:
183     JMenu                     _type_menu;
184     JCheckBoxMenuItem         _rectangular_type_cbmi;
185     JCheckBoxMenuItem         _triangular_type_cbmi;
186     JCheckBoxMenuItem         _curved_type_cbmi;
187     JCheckBoxMenuItem         _convex_type_cbmi;
188     JCheckBoxMenuItem         _euro_type_cbmi;
189     JCheckBoxMenuItem         _rounded_type_cbmi;
190     JCheckBoxMenuItem         _unrooted_type_cbmi;
191     JCheckBoxMenuItem         _circular_type_cbmi;
192     // view as text menu:
193     JMenuItem                 _view_as_NH_item;
194     JMenuItem                 _view_as_NHX_item;
195     JMenuItem                 _view_as_XML_item;
196     JMenuItem                 _view_as_nexus_item;
197     JMenuItem                 _display_basic_information_item;
198     // help menu:
199     JMenuItem                 _about_item;
200     JMenuItem                 _help_item;
201     JMenuItem                 _website_item;
202     JMenuItem                 _phyloxml_website_item;
203     JMenuItem                 _phyloxml_ref_item;
204     JMenuItem                 _aptx_ref_item;
205     // Handy pointers to child components:
206     MainPanel                 _mainpanel;
207     Container                 _contentpane;
208     TextFrame                 _textframe;
209     Configuration             _configuration;
210     JMenuItem                 _remove_branch_color_item;
211     Options                   _options;
212
213     MainFrame() {
214         // Empty constructor.
215     }
216
217     /**
218      * Action performed.
219      */
220     public void actionPerformed( final ActionEvent e ) {
221         final Object o = e.getSource();
222         boolean is_applet = false;
223         JApplet applet = null;
224         if ( getCurrentTreePanel() != null ) {
225             is_applet = getCurrentTreePanel().isApplet();
226             if ( is_applet ) {
227                 applet = getCurrentTreePanel().obtainApplet();
228             }
229         }
230         if ( o == _open_url_item ) {
231             readPhylogeniesFromURL();
232         }
233         else if ( o == _exit_item ) {
234             close();
235         }
236         else if ( o == _taxcolor_item ) {
237             taxColor();
238         }
239         else if ( o == _confcolor_item ) {
240             confColor();
241         }
242         else if ( o == _color_rank_jmi ) {
243             colorRank();
244         }
245         else if ( o == _infer_common_sn_names_item ) {
246             if ( isSubtreeDisplayed() ) {
247                 return;
248             }
249             if ( getCurrentTreePanel() != null ) {
250                 getCurrentTreePanel().inferCommonPartOfScientificNames();
251             }
252         }
253         else if ( o == _collapse_species_specific_subtrees ) {
254             if ( isSubtreeDisplayed() ) {
255                 return;
256             }
257             if ( getCurrentTreePanel() != null ) {
258                 getCurrentTreePanel().collapseSpeciesSpecificSubtrees();
259             }
260         }
261         else if ( o == _remove_branch_color_item ) {
262             if ( isSubtreeDisplayed() ) {
263                 return;
264             }
265             removeBranchColors();
266         }
267         else if ( o == _midpoint_root_item ) {
268             if ( isSubtreeDisplayed() ) {
269                 return;
270             }
271             midpointRoot();
272         }
273         else if ( o == _switch_colors_mi ) {
274             switchColors();
275         }
276         else if ( o == _display_basic_information_item ) {
277             displayBasicInformation();
278         }
279         else if ( o == _view_as_NH_item ) {
280             viewAsNH();
281         }
282         else if ( o == _view_as_NHX_item ) {
283             viewAsNHX();
284         }
285         else if ( o == _view_as_XML_item ) {
286             viewAsXML();
287         }
288         else if ( o == _view_as_nexus_item ) {
289             viewAsNexus();
290         }
291         else if ( o == _super_tiny_fonts_item ) {
292             if ( getCurrentTreePanel() != null ) {
293                 getCurrentTreePanel().setSuperTinyFonts();
294                 getCurrentTreePanel().repaint();
295             }
296         }
297         else if ( o == _tiny_fonts_item ) {
298             if ( getCurrentTreePanel() != null ) {
299                 getCurrentTreePanel().setTinyFonts();
300                 getCurrentTreePanel().repaint();
301             }
302         }
303         else if ( o == _small_fonts_item ) {
304             if ( getCurrentTreePanel() != null ) {
305                 getCurrentTreePanel().setSmallFonts();
306                 getCurrentTreePanel().repaint();
307             }
308         }
309         else if ( o == _medium_fonts_item ) {
310             if ( getCurrentTreePanel() != null ) {
311                 getCurrentTreePanel().setMediumFonts();
312                 getCurrentTreePanel().repaint();
313             }
314         }
315         else if ( o == _large_fonts_item ) {
316             if ( getCurrentTreePanel() != null ) {
317                 getCurrentTreePanel().setLargeFonts();
318                 getCurrentTreePanel().repaint();
319             }
320         }
321         else if ( o == _choose_font_mi ) {
322             chooseFont();
323         }
324         else if ( o == _choose_minimal_confidence_mi ) {
325             chooseMinimalConfidence();
326         }
327         else if ( o == _choose_node_size_mi ) {
328             chooseNodeSize( getOptions(), this );
329         }
330         else if ( o == _overview_placment_mi ) {
331             MainFrame.cycleOverview( getOptions(), getCurrentTreePanel() );
332         }
333         else if ( o == _cycle_node_fill_mi ) {
334             MainFrame.cycleNodeFill( getOptions(), getCurrentTreePanel() );
335         }
336         else if ( o == _cycle_node_shape_mi ) {
337             MainFrame.cycleNodeShape( getOptions(), getCurrentTreePanel() );
338         }
339         else if ( o == _screen_antialias_cbmi ) {
340             updateOptions( getOptions() );
341             updateScreenTextAntialias( getMainPanel().getTreePanels() );
342         }
343         else if ( o == _background_gradient_cbmi ) {
344             updateOptions( getOptions() );
345         }
346         else if ( o == _show_domain_labels ) {
347             updateOptions( getOptions() );
348         }
349         else if ( o == _abbreviate_scientific_names ) {
350             updateOptions( getOptions() );
351         }
352         else if ( o == _color_labels_same_as_parent_branch ) {
353             updateOptions( getOptions() );
354         }
355         else if ( o == _show_default_node_shapes_cbmi ) {
356             updateOptions( getOptions() );
357         }
358         else if ( o == _taxonomy_colorize_node_shapes_cbmi ) {
359             updateOptions( getOptions() );
360         }
361         else if ( o == _non_lined_up_cladograms_rbmi ) {
362             updateOptions( getOptions() );
363             showWhole();
364         }
365         else if ( o == _uniform_cladograms_rbmi ) {
366             updateOptions( getOptions() );
367             showWhole();
368         }
369         else if ( o == _ext_node_dependent_cladogram_rbmi ) {
370             updateOptions( getOptions() );
371             showWhole();
372         }
373         else if ( o == _search_case_senstive_cbmi ) {
374             updateOptions( getOptions() );
375             getMainPanel().getControlPanel().search();
376         }
377         else if ( o == _search_whole_words_only_cbmi ) {
378             updateOptions( getOptions() );
379             getMainPanel().getControlPanel().search();
380         }
381         else if ( o == _inverse_search_result_cbmi ) {
382             updateOptions( getOptions() );
383             getMainPanel().getControlPanel().search();
384         }
385         else if ( o == _show_scale_cbmi ) {
386             updateOptions( getOptions() );
387         }
388         else if ( o == _show_branch_length_values_cbmi ) {
389             updateOptions( getOptions() );
390         }
391         else if ( o == _show_confidence_stddev_cbmi ) {
392             updateOptions( getOptions() );
393         }
394         else if ( o == _use_brackets_for_conf_in_nh_export_cbmi ) {
395             if ( _use_brackets_for_conf_in_nh_export_cbmi.isSelected() ) {
396                 _use_internal_names_for_conf_in_nh_export_cbmi.setSelected( false );
397             }
398             updateOptions( getOptions() );
399         }
400         else if ( o == _use_internal_names_for_conf_in_nh_export_cbmi ) {
401             if ( _use_internal_names_for_conf_in_nh_export_cbmi.isSelected() ) {
402                 _use_brackets_for_conf_in_nh_export_cbmi.setSelected( false );
403             }
404             updateOptions( getOptions() );
405         }
406         else if ( o == _label_direction_cbmi ) {
407             updateOptions( getOptions() );
408         }
409         else if ( o == _show_overview_cbmi ) {
410             updateOptions( getOptions() );
411             if ( getCurrentTreePanel() != null ) {
412                 getCurrentTreePanel().updateOvSizes();
413             }
414         }
415         else if ( ( o == _rectangular_type_cbmi ) || ( o == _triangular_type_cbmi ) || ( o == _curved_type_cbmi )
416                 || ( o == _convex_type_cbmi ) || ( o == _euro_type_cbmi ) || ( o == _rounded_type_cbmi )
417                 || ( o == _unrooted_type_cbmi ) || ( o == _circular_type_cbmi ) ) {
418             typeChanged( o );
419         }
420         else if ( o == _about_item ) {
421             about();
422         }
423         else if ( o == _help_item ) {
424             help( getConfiguration().getWebLinks() );
425         }
426         else if ( o == _website_item ) {
427             try {
428                 AptxUtil.openWebsite( Constants.APTX_WEB_SITE, is_applet, applet );
429             }
430             catch ( final IOException e1 ) {
431                 ForesterUtil.printErrorMessage( Constants.PRG_NAME, e1.toString() );
432             }
433         }
434         else if ( o == _phyloxml_website_item ) {
435             try {
436                 AptxUtil.openWebsite( Constants.PHYLOXML_WEB_SITE, is_applet, applet );
437             }
438             catch ( final IOException e1 ) {
439                 ForesterUtil.printErrorMessage( Constants.PRG_NAME, e1.toString() );
440             }
441         }
442         else if ( o == _aptx_ref_item ) {
443             try {
444                 AptxUtil.openWebsite( Constants.APTX_REFERENCE_URL, is_applet, applet );
445             }
446             catch ( final IOException e1 ) {
447                 ForesterUtil.printErrorMessage( Constants.PRG_NAME, e1.toString() );
448             }
449         }
450         else if ( o == _phyloxml_ref_item ) {
451             try {
452                 AptxUtil.openWebsite( Constants.PHYLOXML_REFERENCE_URL, is_applet, applet );
453             }
454             catch ( final IOException e1 ) {
455                 ForesterUtil.printErrorMessage( Constants.PRG_NAME, e1.toString() );
456             }
457         }
458         else {
459             if ( _load_phylogeny_from_webservice_menu_items != null ) {
460                 for( int i = 0; i < _load_phylogeny_from_webservice_menu_items.length; ++i ) {
461                     if ( o == _load_phylogeny_from_webservice_menu_items[ i ] ) {
462                         readPhylogeniesFromWebservice( i );
463                     }
464                 }
465             }
466         }
467         _contentpane.repaint();
468     }
469
470     boolean isSubtreeDisplayed() {
471         if ( getCurrentTreePanel() != null ) {
472             if ( getCurrentTreePanel().isCurrentTreeIsSubtree() ) {
473                 JOptionPane
474                         .showMessageDialog( this,
475                                             "This operation can only be performed on a complete tree, not on the currently displayed sub-tree only.",
476                                             "Operation can not be exectuted on a sub-tree",
477                                             JOptionPane.WARNING_MESSAGE );
478                 return true;
479             }
480         }
481         return false;
482     }
483
484     void activateSaveAllIfNeeded() {
485         if ( ( getMainPanel().getTabbedPane() != null ) && ( getMainPanel().getTabbedPane().getTabCount() > 1 ) ) {
486             _save_all_item.setEnabled( true );
487         }
488         else {
489             _save_all_item.setEnabled( false );
490         }
491     }
492
493     void buildFileMenu() {
494         _file_jmenu = createMenu( "File", getConfiguration() );
495         _file_jmenu.add( _open_url_item = new JMenuItem( "Read tree from URL/webservice..." ) );
496         _file_jmenu.addSeparator();
497         _file_jmenu.add( _exit_item = new JMenuItem( "Exit" ) );
498         customizeJMenuItem( _open_url_item );
499         customizeJMenuItem( _exit_item );
500         _jmenubar.add( _file_jmenu );
501     }
502
503     void buildFontSizeMenu() {
504         _font_size_menu = createMenu( FONT_SIZE_MENU_LABEL, getConfiguration() );
505         _font_size_menu.add( _super_tiny_fonts_item = new JMenuItem( "Super Tiny Fonts" ) );
506         _font_size_menu.add( _tiny_fonts_item = new JMenuItem( "Tiny Fonts" ) );
507         _font_size_menu.add( _small_fonts_item = new JMenuItem( "Small Fonts" ) );
508         _font_size_menu.add( _medium_fonts_item = new JMenuItem( "Medium Fonts" ) );
509         _font_size_menu.add( _large_fonts_item = new JMenuItem( "Large Fonts" ) );
510         customizeJMenuItem( _super_tiny_fonts_item );
511         customizeJMenuItem( _tiny_fonts_item );
512         customizeJMenuItem( _small_fonts_item );
513         customizeJMenuItem( _medium_fonts_item );
514         customizeJMenuItem( _large_fonts_item );
515         _jmenubar.add( _font_size_menu );
516     }
517
518     void buildHelpMenu() {
519         _help_jmenu = createMenu( "Help", getConfiguration() );
520         _help_jmenu.add( _help_item = new JMenuItem( "Help" ) );
521         _help_jmenu.add( _website_item = new JMenuItem( "Archaeopteryx Home" ) );
522         _aptx_ref_item = new JMenuItem( "Archaeopteryx Reference" );
523         _help_jmenu.add( _phyloxml_website_item = new JMenuItem( "phyloXML Home" ) );
524         _help_jmenu.add( _phyloxml_ref_item = new JMenuItem( "phyloXML Reference" ) );
525         _help_jmenu.addSeparator();
526         _help_jmenu.add( _about_item = new JMenuItem( "About" ) );
527         customizeJMenuItem( _help_item );
528         customizeJMenuItem( _website_item );
529         customizeJMenuItem( _phyloxml_website_item );
530         customizeJMenuItem( _aptx_ref_item );
531         customizeJMenuItem( _phyloxml_ref_item );
532         customizeJMenuItem( _about_item );
533         _phyloxml_ref_item.setToolTipText( PHYLOXML_REF_TOOL_TIP );
534         _aptx_ref_item.setToolTipText( APTX_REF_TOOL_TIP );
535         _jmenubar.add( _help_jmenu );
536     }
537
538     void buildTypeMenu() {
539         _type_menu = createMenu( TYPE_MENU_HEADER, getConfiguration() );
540         _type_menu.add( _rectangular_type_cbmi = new JCheckBoxMenuItem( MainFrame.RECTANGULAR_TYPE_CBMI_LABEL ) );
541         _type_menu.add( _euro_type_cbmi = new JCheckBoxMenuItem( MainFrame.EURO_TYPE_CBMI_LABEL ) );
542         _type_menu.add( _rounded_type_cbmi = new JCheckBoxMenuItem( MainFrame.ROUNDED_TYPE_CBMI_LABEL ) );
543         _type_menu.add( _curved_type_cbmi = new JCheckBoxMenuItem( MainFrame.CURVED_TYPE_CBMI_LABEL ) );
544         _type_menu.add( _triangular_type_cbmi = new JCheckBoxMenuItem( MainFrame.TRIANGULAR_TYPE_CBMI_LABEL ) );
545         _type_menu.add( _convex_type_cbmi = new JCheckBoxMenuItem( MainFrame.CONVEX_TYPE_CBMI_LABEL ) );
546         _type_menu.add( _unrooted_type_cbmi = new JCheckBoxMenuItem( MainFrame.UNROOTED_TYPE_CBMI_LABEL ) );
547         _type_menu.add( _circular_type_cbmi = new JCheckBoxMenuItem( MainFrame.CIRCULAR_TYPE_CBMI_LABEL ) );
548         customizeCheckBoxMenuItem( _rectangular_type_cbmi, false );
549         customizeCheckBoxMenuItem( _triangular_type_cbmi, false );
550         customizeCheckBoxMenuItem( _euro_type_cbmi, false );
551         customizeCheckBoxMenuItem( _rounded_type_cbmi, false );
552         customizeCheckBoxMenuItem( _curved_type_cbmi, false );
553         customizeCheckBoxMenuItem( _convex_type_cbmi, false );
554         customizeCheckBoxMenuItem( _unrooted_type_cbmi, false );
555         customizeCheckBoxMenuItem( _circular_type_cbmi, false );
556         _unrooted_type_cbmi.setToolTipText( MainFrame.USE_MOUSEWHEEL_SHIFT_TO_ROTATE );
557         _circular_type_cbmi.setToolTipText( MainFrame.USE_MOUSEWHEEL_SHIFT_TO_ROTATE );
558         initializeTypeMenu( getOptions() );
559         _jmenubar.add( _type_menu );
560     }
561
562     void buildViewMenu() {
563         _view_jmenu = createMenu( "View", getConfiguration() );
564         _view_jmenu.add( _display_basic_information_item = new JMenuItem( "Display Basic Information" ) );
565         _view_jmenu.addSeparator();
566         _view_jmenu.add( _view_as_XML_item = new JMenuItem( "View as phyloXML" ) );
567         _view_jmenu.add( _view_as_NH_item = new JMenuItem( "View as Newick" ) );
568         _view_jmenu.add( _view_as_NHX_item = new JMenuItem( "View as NHX" ) );
569         _view_jmenu.add( _view_as_nexus_item = new JMenuItem( "View as Nexus" ) );
570         customizeJMenuItem( _display_basic_information_item );
571         customizeJMenuItem( _view_as_NH_item );
572         customizeJMenuItem( _view_as_NHX_item );
573         customizeJMenuItem( _view_as_XML_item );
574         customizeJMenuItem( _view_as_nexus_item );
575         _jmenubar.add( _view_jmenu );
576     }
577
578     private void chooseFont() {
579         final FontChooser fc = new FontChooser();
580         fc.setFont( getMainPanel().getTreeFontSet().getLargeFont() );
581         fc.showDialog( this, "Select the Base Font" );
582         getMainPanel().getTreeFontSet().setBaseFont( fc.getFont() );
583     }
584
585     private void chooseMinimalConfidence() {
586         final String s = ( String ) JOptionPane
587                 .showInputDialog( this,
588                                   "Please enter the minimum for confidence values to be displayed.\n"
589                                           + "[current value: " + getOptions().getMinConfidenceValue() + "]\n",
590                                   "Minimal Confidence Value",
591                                   JOptionPane.QUESTION_MESSAGE,
592                                   null,
593                                   null,
594                                   getOptions().getMinConfidenceValue() );
595         if ( !ForesterUtil.isEmpty( s ) ) {
596             boolean success = true;
597             double m = 0.0;
598             final String m_str = s.trim();
599             if ( !ForesterUtil.isEmpty( m_str ) ) {
600                 try {
601                     m = Double.parseDouble( m_str );
602                 }
603                 catch ( final Exception ex ) {
604                     success = false;
605                 }
606             }
607             else {
608                 success = false;
609             }
610             if ( success && ( m >= 0.0 ) ) {
611                 getOptions().setMinConfidenceValue( m );
612             }
613         }
614     }
615
616     static void chooseNodeSize( final Options options, final Component parent ) {
617         final String s = ( String ) JOptionPane.showInputDialog( parent,
618                                                                  "Please enter the default size for node shapes.\n"
619                                                                          + "[current value: "
620                                                                          + options.getDefaultNodeShapeSize() + "]\n",
621                                                                  "Node Shape Size",
622                                                                  JOptionPane.QUESTION_MESSAGE,
623                                                                  null,
624                                                                  null,
625                                                                  options.getDefaultNodeShapeSize() );
626         if ( !ForesterUtil.isEmpty( s ) ) {
627             boolean success = true;
628             double m = 0.0;
629             final String m_str = s.trim();
630             if ( !ForesterUtil.isEmpty( m_str ) ) {
631                 try {
632                     m = Double.parseDouble( m_str );
633                 }
634                 catch ( final Exception ex ) {
635                     success = false;
636                 }
637             }
638             else {
639                 success = false;
640             }
641             if ( success && ( m >= 0.0 ) ) {
642                 final short size = ForesterUtil.roundToShort( m );
643                 if ( size >= 0.0 ) {
644                     options.setDefaultNodeShapeSize( size );
645                 }
646             }
647         }
648     }
649
650     void close() {
651         removeTextFrame();
652         if ( _mainpanel != null ) {
653             _mainpanel.terminate();
654         }
655         if ( _contentpane != null ) {
656             _contentpane.removeAll();
657         }
658         setVisible( false );
659         dispose();
660     }
661
662     void confColor() {
663         if ( _mainpanel.getCurrentTreePanel() != null ) {
664             _mainpanel.getCurrentTreePanel().confColor();
665         }
666     }
667
668     void colorRank() {
669         if ( _mainpanel.getCurrentTreePanel() != null ) {
670             final String[] ranks = AptxUtil.getAllPossibleRanks();
671             final String rank = ( String ) JOptionPane
672                     .showInputDialog( this,
673                                       "What rank should the colorization be based on",
674                                       "Rank Selection",
675                                       JOptionPane.QUESTION_MESSAGE,
676                                       null,
677                                       ranks,
678                                       null );
679             if ( !ForesterUtil.isEmpty( rank ) ) {
680                 _mainpanel.getCurrentTreePanel().colorRank( rank );
681             }
682         }
683     }
684
685     void customizeCheckBoxMenuItem( final JCheckBoxMenuItem item, final boolean is_selected ) {
686         if ( item != null ) {
687             item.setFont( MainFrame.menu_font );
688             if ( !getConfiguration().isUseNativeUI() ) {
689                 item.setBackground( getConfiguration().getGuiMenuBackgroundColor() );
690                 item.setForeground( getConfiguration().getGuiMenuTextColor() );
691             }
692             item.setSelected( is_selected );
693             item.addActionListener( this );
694         }
695     }
696
697     void customizeJMenuItem( final JMenuItem jmi ) {
698         if ( jmi != null ) {
699             jmi.setFont( MainFrame.menu_font );
700             if ( !getConfiguration().isUseNativeUI() ) {
701                 jmi.setBackground( getConfiguration().getGuiMenuBackgroundColor() );
702                 jmi.setForeground( getConfiguration().getGuiMenuTextColor() );
703             }
704             jmi.addActionListener( this );
705         }
706     }
707
708     void customizeRadioButtonMenuItem( final JRadioButtonMenuItem item, final boolean is_selected ) {
709         if ( item != null ) {
710             item.setFont( MainFrame.menu_font );
711             if ( !getConfiguration().isUseNativeUI() ) {
712                 item.setBackground( getConfiguration().getGuiMenuBackgroundColor() );
713                 item.setForeground( getConfiguration().getGuiMenuTextColor() );
714             }
715             item.setSelected( is_selected );
716             item.addActionListener( this );
717         }
718     }
719
720     void exceptionOccuredDuringOpenFile( final Exception e ) {
721         try {
722             _mainpanel.getCurrentTreePanel().setArrowCursor();
723         }
724         catch ( final Exception ex ) {
725             // Do nothing.
726         }
727         JOptionPane.showMessageDialog( this,
728                                        ForesterUtil.wordWrap( e.getLocalizedMessage(), 80 ),
729                                        "Error during File|Open",
730                                        JOptionPane.ERROR_MESSAGE );
731     }
732
733     void exceptionOccuredDuringSaveAs( final Exception e ) {
734         try {
735             _mainpanel.getCurrentTreePanel().setArrowCursor();
736         }
737         catch ( final Exception ex ) {
738             // Do nothing.
739         }
740         JOptionPane.showMessageDialog( this, "Exception" + e, "Error during File|SaveAs", JOptionPane.ERROR_MESSAGE );
741     }
742
743     boolean GAndSDoHaveMoreThanOneSpeciesInComman( final Phylogeny gene_tree ) {
744         if ( ( gene_tree == null ) || gene_tree.isEmpty() ) {
745             JOptionPane.showMessageDialog( this,
746                                            "Gene tree and species tree have no species in common.",
747                                            "Error during SDI",
748                                            JOptionPane.ERROR_MESSAGE );
749             return false;
750         }
751         else if ( gene_tree.getNumberOfExternalNodes() < 2 ) {
752             JOptionPane.showMessageDialog( this,
753                                            "Gene tree and species tree have only one species in common.",
754                                            "Error during SDI",
755                                            JOptionPane.ERROR_MESSAGE );
756             return false;
757         }
758         else {
759             return true;
760         }
761     }
762
763     public Configuration getConfiguration() {
764         return _configuration;
765     }
766
767     TreePanel getCurrentTreePanel() {
768         return getMainPanel().getCurrentTreePanel();
769     }
770
771     JMenu getHelpMenu() {
772         return _help_jmenu;
773     }
774
775     JCheckBoxMenuItem getlabelDirectionCbmi() {
776         return _label_direction_cbmi;
777     }
778
779     MainPanel getMainPanel() {
780         return _mainpanel;
781     }
782
783     JMenuBar getMenuBarOfMainFrame() {
784         return _jmenubar;
785     }
786
787     public Options getOptions() {
788         return _options;
789     }
790
791     void initializeTypeMenu( final Options options ) {
792         setTypeMenuToAllUnselected();
793         switch ( options.getPhylogenyGraphicsType() ) {
794             case CONVEX:
795                 _convex_type_cbmi.setSelected( true );
796                 break;
797             case CURVED:
798                 _curved_type_cbmi.setSelected( true );
799                 break;
800             case EURO_STYLE:
801                 _euro_type_cbmi.setSelected( true );
802                 break;
803             case ROUNDED:
804                 _rounded_type_cbmi.setSelected( true );
805                 break;
806             case TRIANGULAR:
807                 _triangular_type_cbmi.setSelected( true );
808                 break;
809             case UNROOTED:
810                 _unrooted_type_cbmi.setSelected( true );
811                 break;
812             case CIRCULAR:
813                 _circular_type_cbmi.setSelected( true );
814                 break;
815             default:
816                 _rectangular_type_cbmi.setSelected( true );
817                 break;
818         }
819     }
820
821     void midpointRoot() {
822         if ( _mainpanel.getCurrentTreePanel() != null ) {
823             _mainpanel.getCurrentTreePanel().midpointRoot();
824         }
825     }
826
827     abstract void readPhylogeniesFromURL();
828
829     void readPhylogeniesFromWebservice( final int i ) {
830         final UrlTreeReader reader = new UrlTreeReader( this, i );
831         new Thread( reader ).start();
832     }
833
834     private void removeBranchColors() {
835         if ( getMainPanel().getCurrentPhylogeny() != null ) {
836             AptxUtil.removeBranchColors( getMainPanel().getCurrentPhylogeny() );
837         }
838     }
839
840     void removeTextFrame() {
841         if ( _textframe != null ) {
842             _textframe.close();
843             _textframe = null;
844         }
845     }
846
847     void setConfiguration( final Configuration configuration ) {
848         _configuration = configuration;
849     }
850
851     void setOptions( final Options options ) {
852         _options = options;
853     }
854
855     void setSelectedTypeInTypeMenu( final PHYLOGENY_GRAPHICS_TYPE type ) {
856         setTypeMenuToAllUnselected();
857         switch ( type ) {
858             case CIRCULAR:
859                 _circular_type_cbmi.setSelected( true );
860                 break;
861             case CONVEX:
862                 _convex_type_cbmi.setSelected( true );
863                 break;
864             case CURVED:
865                 _curved_type_cbmi.setSelected( true );
866                 break;
867             case EURO_STYLE:
868                 _euro_type_cbmi.setSelected( true );
869                 break;
870             case ROUNDED:
871                 _rounded_type_cbmi.setSelected( true );
872                 break;
873             case RECTANGULAR:
874                 _rectangular_type_cbmi.setSelected( true );
875                 break;
876             case TRIANGULAR:
877                 _triangular_type_cbmi.setSelected( true );
878                 break;
879             case UNROOTED:
880                 _unrooted_type_cbmi.setSelected( true );
881                 break;
882             default:
883                 throw new IllegalArgumentException( "unknown type: " + type );
884         }
885     }
886
887     void setTypeMenuToAllUnselected() {
888         _convex_type_cbmi.setSelected( false );
889         _curved_type_cbmi.setSelected( false );
890         _euro_type_cbmi.setSelected( false );
891         _rounded_type_cbmi.setSelected( false );
892         _triangular_type_cbmi.setSelected( false );
893         _rectangular_type_cbmi.setSelected( false );
894         _unrooted_type_cbmi.setSelected( false );
895         _circular_type_cbmi.setSelected( false );
896     }
897
898     public void showWhole() {
899         _mainpanel.getControlPanel().showWhole();
900     }
901
902     void switchColors() {
903         final TreeColorSet colorset = _mainpanel.getTreeColorSet();
904         final ColorSchemeChooser csc = new ColorSchemeChooser( getMainPanel(), colorset );
905         csc.setVisible( true );
906     }
907
908     void taxColor() {
909         if ( _mainpanel.getCurrentTreePanel() != null ) {
910             _mainpanel.getCurrentTreePanel().taxColor();
911         }
912     }
913
914     void typeChanged( final Object o ) {
915         updateTypeCheckboxes( getOptions(), o );
916         updateOptions( getOptions() );
917         if ( getCurrentTreePanel() != null ) {
918             final PHYLOGENY_GRAPHICS_TYPE previous_type = getCurrentTreePanel().getPhylogenyGraphicsType();
919             final PHYLOGENY_GRAPHICS_TYPE new_type = getOptions().getPhylogenyGraphicsType();
920             if ( ( ( previous_type == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) && ( new_type != PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) )
921                     || ( ( previous_type == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) && ( new_type != PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) )
922                     || ( ( previous_type != PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) && ( new_type == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) )
923                     || ( ( previous_type != PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) && ( new_type == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) ) ) {
924                 getCurrentTreePanel().getControlPanel().showWhole();
925             }
926             if ( getCurrentTreePanel().isPhyHasBranchLengths() && ( new_type != PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) ) {
927                 getCurrentTreePanel().getControlPanel().setDrawPhylogramEnabled( true );
928             }
929             else {
930                 getCurrentTreePanel().getControlPanel().setDrawPhylogramEnabled( false );
931             }
932             getCurrentTreePanel().setPhylogenyGraphicsType( getOptions().getPhylogenyGraphicsType() );
933             updateScreenTextAntialias( getMainPanel().getTreePanels() );
934             if ( getCurrentTreePanel().getControlPanel().getDynamicallyHideData() != null ) {
935                 if ( new_type == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) {
936                     getCurrentTreePanel().getControlPanel().getDynamicallyHideData().setEnabled( false );
937                 }
938                 else {
939                     getCurrentTreePanel().getControlPanel().getDynamicallyHideData().setEnabled( true );
940                 }
941             }
942         }
943     }
944
945     void updateOptions( final Options options ) {
946         options.setAntialiasScreen( ( _screen_antialias_cbmi != null ) && _screen_antialias_cbmi.isSelected() );
947         options.setBackgroundColorGradient( ( _background_gradient_cbmi != null )
948                 && _background_gradient_cbmi.isSelected() );
949         options.setShowDomainLabels( ( _show_domain_labels != null ) && _show_domain_labels.isSelected() );
950         options.setAbbreviateScientificTaxonNames( ( _abbreviate_scientific_names != null )
951                 && _abbreviate_scientific_names.isSelected() );
952         options.setColorLabelsSameAsParentBranch( ( _color_labels_same_as_parent_branch != null )
953                 && _color_labels_same_as_parent_branch.isSelected() );
954         options.setShowDefaultNodeShapes( ( _show_default_node_shapes_cbmi != null )
955                 && _show_default_node_shapes_cbmi.isSelected() );
956         options.setTaxonomyColorizeNodeShapes( ( _taxonomy_colorize_node_shapes_cbmi != null )
957                 && _taxonomy_colorize_node_shapes_cbmi.isSelected() );
958         if ( ( _non_lined_up_cladograms_rbmi != null ) && ( _non_lined_up_cladograms_rbmi.isSelected() ) ) {
959             options.setCladogramType( CLADOGRAM_TYPE.NON_LINED_UP );
960         }
961         else if ( ( _uniform_cladograms_rbmi != null ) && ( _uniform_cladograms_rbmi.isSelected() ) ) {
962             options.setCladogramType( CLADOGRAM_TYPE.TOTAL_NODE_SUM_DEP );
963         }
964         else if ( ( _ext_node_dependent_cladogram_rbmi != null ) && ( _ext_node_dependent_cladogram_rbmi.isSelected() ) ) {
965             options.setCladogramType( CLADOGRAM_TYPE.EXT_NODE_SUM_DEP );
966         }
967         options.setSearchCaseSensitive( ( _search_case_senstive_cbmi != null )
968                 && _search_case_senstive_cbmi.isSelected() );
969         if ( ( _show_scale_cbmi != null ) && _show_scale_cbmi.isEnabled() ) {
970             options.setShowScale( _show_scale_cbmi.isSelected() );
971         }
972         if ( _label_direction_cbmi != null ) {
973             if ( _label_direction_cbmi.isSelected() ) {
974                 options.setNodeLabelDirection( NODE_LABEL_DIRECTION.RADIAL );
975             }
976             else {
977                 options.setNodeLabelDirection( NODE_LABEL_DIRECTION.HORIZONTAL );
978             }
979         }
980         options.setShowOverview( ( _show_overview_cbmi != null ) && _show_overview_cbmi.isSelected() );
981         options.setShowConfidenceStddev( ( _show_confidence_stddev_cbmi != null )
982                 && _show_confidence_stddev_cbmi.isSelected() );
983         if ( ( _show_branch_length_values_cbmi != null ) && _show_branch_length_values_cbmi.isEnabled() ) {
984             options.setShowBranchLengthValues( _show_branch_length_values_cbmi.isSelected() );
985         }
986         options.setPrintUsingActualSize( ( _print_using_actual_size_cbmi != null )
987                 && ( _print_using_actual_size_cbmi.isSelected() ) );
988         options.setGraphicsExportUsingActualSize( ( _graphics_export_using_actual_size_cbmi != null )
989                 && ( _graphics_export_using_actual_size_cbmi.isSelected() ) );
990         options.setAntialiasPrint( ( _antialias_print_cbmi != null ) && _antialias_print_cbmi.isSelected() );
991         if ( ( _use_brackets_for_conf_in_nh_export_cbmi != null )
992                 && _use_brackets_for_conf_in_nh_export_cbmi.isSelected() ) {
993             options.setNhConversionSupportValueStyle( NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS );
994         }
995         else if ( ( _use_internal_names_for_conf_in_nh_export_cbmi != null )
996                 && _use_internal_names_for_conf_in_nh_export_cbmi.isSelected() ) {
997             options.setNhConversionSupportValueStyle( NH_CONVERSION_SUPPORT_VALUE_STYLE.AS_INTERNAL_NODE_NAMES );
998         }
999         else {
1000             options.setNhConversionSupportValueStyle( NH_CONVERSION_SUPPORT_VALUE_STYLE.NONE );
1001         }
1002         options.setPrintBlackAndWhite( ( _print_black_and_white_cbmi != null )
1003                 && _print_black_and_white_cbmi.isSelected() );
1004         options.setInternalNumberAreConfidenceForNhParsing( ( _internal_number_are_confidence_for_nh_parsing_cbmi != null )
1005                 && _internal_number_are_confidence_for_nh_parsing_cbmi.isSelected() );
1006         options.setExtractPfamTaxonomyCodesInNhParsing( ( _extract_pfam_style_tax_codes_cbmi != null )
1007                 && _extract_pfam_style_tax_codes_cbmi.isSelected() );
1008         options.setReplaceUnderscoresInNhParsing( ( _replace_underscores_cbmi != null )
1009                 && _replace_underscores_cbmi.isSelected() );
1010         options.setMatchWholeTermsOnly( ( _search_whole_words_only_cbmi != null )
1011                 && _search_whole_words_only_cbmi.isSelected() );
1012         options.setInverseSearchResult( ( _inverse_search_result_cbmi != null )
1013                 && _inverse_search_result_cbmi.isSelected() );
1014         if ( _graphics_export_visible_only_cbmi != null ) {
1015             options.setGraphicsExportVisibleOnly( _graphics_export_visible_only_cbmi.isSelected() );
1016             if ( _graphics_export_visible_only_cbmi.isSelected() && ( _graphics_export_using_actual_size_cbmi != null ) ) {
1017                 _graphics_export_using_actual_size_cbmi.setSelected( true );
1018                 _graphics_export_using_actual_size_cbmi.setEnabled( false );
1019             }
1020             else {
1021                 _graphics_export_using_actual_size_cbmi.setEnabled( true );
1022             }
1023         }
1024         if ( ( _rectangular_type_cbmi != null ) && _rectangular_type_cbmi.isSelected() ) {
1025             options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR );
1026         }
1027         else if ( ( _triangular_type_cbmi != null ) && _triangular_type_cbmi.isSelected() ) {
1028             options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.TRIANGULAR );
1029         }
1030         else if ( ( _curved_type_cbmi != null ) && _curved_type_cbmi.isSelected() ) {
1031             options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CURVED );
1032         }
1033         else if ( ( _convex_type_cbmi != null ) && _convex_type_cbmi.isSelected() ) {
1034             options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CONVEX );
1035         }
1036         else if ( ( _euro_type_cbmi != null ) && _euro_type_cbmi.isSelected() ) {
1037             options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE );
1038         }
1039         else if ( ( _rounded_type_cbmi != null ) && _rounded_type_cbmi.isSelected() ) {
1040             options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.ROUNDED );
1041         }
1042         else if ( ( _unrooted_type_cbmi != null ) && _unrooted_type_cbmi.isSelected() ) {
1043             options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.UNROOTED );
1044         }
1045         else if ( ( _circular_type_cbmi != null ) && _circular_type_cbmi.isSelected() ) {
1046             options.setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CIRCULAR );
1047         }
1048     }
1049
1050     void updateTypeCheckboxes( final Options options, final Object o ) {
1051         setTypeMenuToAllUnselected();
1052         ( ( JCheckBoxMenuItem ) o ).setSelected( true );
1053     }
1054
1055     void displayBasicInformation() {
1056         if ( ( _mainpanel.getCurrentPhylogeny() == null ) || _mainpanel.getCurrentPhylogeny().isEmpty() ) {
1057             return;
1058         }
1059         _textframe = TextFrame.instantiate( AptxUtil.crateBasicInformation( _mainpanel.getCurrentPhylogeny() ) );
1060     }
1061
1062     void viewAsNexus() {
1063         removeTextFrame();
1064         if ( ( _mainpanel.getCurrentPhylogeny() == null ) || _mainpanel.getCurrentPhylogeny().isEmpty()
1065                 || ( _mainpanel.getCurrentPhylogeny().getNumberOfExternalNodes() > 20000 ) ) {
1066             return;
1067         }
1068         _textframe = TextFrame.instantiate( _mainpanel.getCurrentPhylogeny().toNexus( getOptions()
1069                 .getNhConversionSupportValueStyle() ) );
1070     }
1071
1072     void viewAsNH() {
1073         removeTextFrame();
1074         if ( ( _mainpanel.getCurrentPhylogeny() == null ) || _mainpanel.getCurrentPhylogeny().isEmpty()
1075                 || ( _mainpanel.getCurrentPhylogeny().getNumberOfExternalNodes() > 20000 ) ) {
1076             return;
1077         }
1078         _textframe = TextFrame.instantiate( _mainpanel.getCurrentPhylogeny()
1079                 .toNewHampshire( false, getOptions().getNhConversionSupportValueStyle() ) );
1080     }
1081
1082     void viewAsNHX() {
1083         removeTextFrame();
1084         if ( ( _mainpanel.getCurrentPhylogeny() == null ) || _mainpanel.getCurrentPhylogeny().isEmpty()
1085                 || ( _mainpanel.getCurrentPhylogeny().getNumberOfExternalNodes() > 10000 ) ) {
1086             return;
1087         }
1088         _textframe = TextFrame.instantiate( _mainpanel.getCurrentPhylogeny().toNewHampshireX() );
1089     }
1090
1091     void viewAsXML() {
1092         removeTextFrame();
1093         if ( ( _mainpanel.getCurrentPhylogeny() != null ) && !_mainpanel.getCurrentPhylogeny().isEmpty()
1094                 && ( _mainpanel.getCurrentPhylogeny().getNumberOfExternalNodes() <= 10000 ) ) {
1095             _textframe = TextFrame.instantiate( _mainpanel.getCurrentPhylogeny().toPhyloXML( 0 ) );
1096         }
1097     }
1098
1099     /**
1100      * Display the about box.
1101      */
1102     static void about() {
1103         final StringBuffer about = new StringBuffer( "Archaeopteryx\nVersion " + Constants.VERSION + "\n" );
1104         about.append( "Copyright (C) 2007-2011 Christian Zmasek\n" );
1105         about.append( "All Rights Reserved\n" );
1106         about.append( "License: GNU Lesser General Public License (LGPL)\n" );
1107         about.append( "Last modified: " + Constants.PRG_DATE + "\n" );
1108         about.append( "phyloXML version : " + ForesterConstants.PHYLO_XML_VERSION + "\n" );
1109         about.append( "phyloXML location: " + ForesterConstants.PHYLO_XML_LOCATION + "\n" );
1110         if ( !ForesterUtil.isEmpty( ForesterUtil.JAVA_VERSION ) && !ForesterUtil.isEmpty( ForesterUtil.JAVA_VENDOR ) ) {
1111             about.append( "[your Java version: " + ForesterUtil.JAVA_VERSION + " " + ForesterUtil.JAVA_VENDOR + "]\n" );
1112         }
1113         if ( !ForesterUtil.isEmpty( ForesterUtil.OS_NAME ) && !ForesterUtil.isEmpty( ForesterUtil.OS_ARCH )
1114                 && !ForesterUtil.isEmpty( ForesterUtil.OS_VERSION ) ) {
1115             about.append( "[your OS: " + ForesterUtil.OS_NAME + " " + ForesterUtil.OS_ARCH + " "
1116                     + ForesterUtil.OS_VERSION + "]\n" );
1117         }
1118         final Runtime rt = java.lang.Runtime.getRuntime();
1119         final long free_memory = rt.freeMemory() / 1000000;
1120         final long total_memory = rt.totalMemory() / 1000000;
1121         about.append( "[free memory: " + free_memory + "MB, total memory: " + total_memory + "MB]\n" );
1122         about.append( "[locale: " + Locale.getDefault() + "]\n" );
1123         about.append( "References:\n" );
1124         about.append( Constants.PHYLOXML_REFERENCE_SHORT + "\n" );
1125         about.append( "For more information & download:\n" );
1126         about.append( Constants.APTX_WEB_SITE + "\n" );
1127         about.append( "Comments: " + Constants.AUTHOR_EMAIL );
1128         JOptionPane.showMessageDialog( null, about, Constants.PRG_NAME, JOptionPane.PLAIN_MESSAGE );
1129     }
1130
1131     static String createCurrentFontDesc( final TreeFontSet tree_font_set ) {
1132         return tree_font_set.getLargeFont().getFamily() + " " + tree_font_set.getLargeFont().getSize();
1133     }
1134
1135     static JMenu createMenu( final String title, final Configuration conf ) {
1136         final JMenu jmenu = new JMenu( title );
1137         if ( !conf.isUseNativeUI() ) {
1138             jmenu.setFont( MainFrame.menu_font );
1139             jmenu.setBackground( conf.getGuiMenuBackgroundColor() );
1140             jmenu.setForeground( conf.getGuiMenuTextColor() );
1141         }
1142         return jmenu;
1143     }
1144
1145     static JMenuItem customizeMenuItemAsLabel( final JMenuItem label, final Configuration configuration ) {
1146         label.setFont( MainFrame.menu_font.deriveFont( Font.BOLD ) );
1147         if ( !configuration.isUseNativeUI() ) {
1148             label.setBackground( configuration.getGuiMenuBackgroundColor() );
1149             label.setForeground( configuration.getGuiMenuTextColor() );
1150             label.setOpaque( true );
1151         }
1152         label.setSelected( false );
1153         label.setEnabled( false );
1154         return label;
1155     }
1156
1157     static void cycleOverview( final Options op, final TreePanel tree_panel ) {
1158         switch ( op.getOvPlacement() ) {
1159             case LOWER_LEFT:
1160                 op.setOvPlacement( Options.OVERVIEW_PLACEMENT_TYPE.UPPER_LEFT );
1161                 break;
1162             case LOWER_RIGHT:
1163                 op.setOvPlacement( Options.OVERVIEW_PLACEMENT_TYPE.LOWER_LEFT );
1164                 break;
1165             case UPPER_LEFT:
1166                 op.setOvPlacement( Options.OVERVIEW_PLACEMENT_TYPE.UPPER_RIGHT );
1167                 break;
1168             case UPPER_RIGHT:
1169                 op.setOvPlacement( Options.OVERVIEW_PLACEMENT_TYPE.LOWER_RIGHT );
1170                 break;
1171             default:
1172                 throw new RuntimeException( "unknown placement: " + op.getOvPlacement() );
1173         }
1174         if ( tree_panel != null ) {
1175             tree_panel.updateOvSettings();
1176         }
1177     }
1178
1179     static void cycleNodeFill( final Options op, final TreePanel tree_panel ) {
1180         switch ( op.getDefaultNodeFill() ) {
1181             case GRADIENT:
1182                 op.setDefaultNodeFill( NodeFill.SOLID );
1183                 break;
1184             case NONE:
1185                 op.setDefaultNodeFill( NodeFill.GRADIENT );
1186                 break;
1187             case SOLID:
1188                 op.setDefaultNodeFill( NodeFill.NONE );
1189                 break;
1190             default:
1191                 throw new RuntimeException( "unknown fill: " + op.getDefaultNodeFill() );
1192         }
1193     }
1194
1195     static void cycleNodeShape( final Options op, final TreePanel tree_panel ) {
1196         switch ( op.getDefaultNodeShape() ) {
1197             case CIRCLE:
1198                 op.setDefaultNodeShape( NodeShape.RECTANGLE );
1199                 break;
1200             case RECTANGLE:
1201                 op.setDefaultNodeShape( NodeShape.CIRCLE );
1202                 break;
1203             default:
1204                 throw new RuntimeException( "unknown shape: " + op.getDefaultNodeShape() );
1205         }
1206     }
1207
1208     static void help( final Map<String, WebLink> weblinks ) {
1209         final StringBuilder sb = new StringBuilder();
1210         sb.append( "Display options\n" );
1211         sb.append( "-------------------\n" );
1212         sb.append( "Use the checkboxes to select types of information to display on the tree.\n\n" );
1213         sb.append( "Clickable tree nodes\n" );
1214         sb.append( "--------------------\n" );
1215         sb.append( "Tree nodes can be clicked, the action is determined by the 'click on node to' menu\n" );
1216         sb.append( "or by right clicking:\n" );
1217         sb.append( "o  Display Node Data -- display information for a node\n" );
1218         sb.append( "o  Collapse/Uncollapse -- collapse and uncollapse subtree from clicked node\n" );
1219         sb.append( "o  Root/Reroot -- change tree root to clicked node\n" );
1220         sb.append( "o  Sub/Super Tree -- toggle between subtree from clicked node and whole tree\n" );
1221         sb.append( "o  Swap Descendants -- switch descendant on either side of clicked node\n" );
1222         sb.append( "o  Colorize Subtree -- color a subtree\n" );
1223         sb.append( "o  Open Sequence Web -- launch a web browser to display sequence information\n" );
1224         sb.append( "o  Open Taxonomy Web -- launch a web browser to display taxonomy information\n" );
1225         sb.append( "-  there may be additional choices depending on this particular setup\n\n" );
1226         sb.append( "Right clicking on a node always displays the information of a node.\n\n" );
1227         sb.append( "Zooming\n" );
1228         sb.append( "---------\n" );
1229         sb.append( "The mouse wheel and the plus and minus keys control zooming.\n" );
1230         sb.append( "Mouse wheel+Ctrl changes the text size.\n" );
1231         sb.append( "Mouse wheel+Shift controls zooming in vertical direction only.\n" );
1232         sb.append( "Use the buttons on the control panel to zoom the tree in and out, horizontally or vertically.\n" );
1233         sb.append( "The entire tree can be fitted into the window by clicking the \"F\" button, or by pressing F, Delete, or Home.\n" );
1234         sb.append( "The up, down, left, and right keys can be used to move the visible part (if zoomed in).\n" );
1235         sb.append( "Up, down, left, and right+Shift can be used to control zooming horizontally and vertically.\n" );
1236         sb.append( "Plus and minus keys+Ctrl change the text size; F+Ctrl, Delete+Ctrl, or Home+Ctrl resets it.\n\n" );
1237         sb.append( "Quick tree manipulation:\n" );
1238         sb.append( "------------------------\n" );
1239         sb.append( "Order Subtrees -- order the tree by branch length\n" );
1240         sb.append( "Uncollapse All -- uncollapse any and all collapsed branches\n\n" );
1241         sb.append( "Memory problems (Java heap space error)\n" );
1242         sb.append( "---------------------------------------\n" );
1243         sb.append( "Since the Java default memory allocation is quite small, it might by necessary (for trees\n" );
1244         sb.append( "with more than approximately 5000 external nodes) to increase the memory which Java can use, with\n" );
1245         sb.append( "the '-Xmx' Java command line option. For example:\n" );
1246         sb.append( "java -Xms32m -Xmx256m -cp path\\to\\forester.jar org.forester.archaeopteryx.Archaeopteryx\n\n" );
1247         if ( ( weblinks != null ) && ( weblinks.size() > 0 ) ) {
1248             sb.append( "Active web links\n" );
1249             sb.append( "--------------------\n" );
1250             for( final String key : weblinks.keySet() ) {
1251                 sb.append( " " + weblinks.get( key ).toString() + "\n" );
1252             }
1253         }
1254         // + "General remarks\n"
1255         // + "---------------\n"
1256         // +
1257         // "o  The application version permits copying to the clipboard \n"
1258         // +
1259         // "    in the \"View\"|\"View as ...\" frame (either by control-c or button press).\n"
1260         // +
1261         // "o  Changes made to a subtree affect this subtree and its subtrees,\n"
1262         // + "    but not any of its parent tree(s).\n"
1263         // +
1264         // "o  Archaeopteryx tries to detect whether the numerical values in a NH tree\n"
1265         // +
1266         // "    are likely to be bootstrap values instead of branch length values.\n\n"
1267         // +
1268         // " Remarks regarding SDI (Speciation Duplication Inference):\n"
1269         // +
1270         // "o  Each external node of the gene tree (in display) needs to be associated with\n"
1271         // +
1272         // "    a species: either directly through the \"Species\" field, or the species\n"
1273         // +
1274         // "    is part of the sequence name in the form \"XXXX_SPECIES\"\n"
1275         // +
1276         // "    (e.g. \"ACON_DROME\" or \"ACON_DROME/123-4489\" which is also acceptable).\n"
1277         // +
1278         // "o  A species tree for each species of the gene tree needs to be loaded with\n"
1279         // +
1280         // "   \"SDI\"|\"Load species tree\" prior the SDI execution.\n"
1281         // +
1282         // "o  !External nodes of the gene tree associated with species not present in\n"
1283         // +
1284         // "    the species tree are REMOVED prior to SDI execution!\n"
1285         // +
1286         // "o  Both the gene tree and the species tree must be completely binary.\n"
1287         // +
1288         // "o  Duplications and speciations are a function of the position of the root.\n"
1289         // +
1290         // "    Hence, after each manual \"Root/Reroot\"ing some duplications will be\n"
1291         // + "    incorrect and need to be inferred again\n"
1292         // +
1293         // "    with: \"SDI\"|\"SDI (Speciation Duplication Inference)\n\n"
1294         sb.append( "\n" );
1295         sb.append( "phyloXML\n" );
1296         sb.append( "-------------------\n" );
1297         sb.append( "Reference: " + Constants.PHYLOXML_REFERENCE + "\n" );
1298         sb.append( "Website: " + Constants.PHYLOXML_WEB_SITE + "\n" );
1299         sb.append( "Version: " + ForesterConstants.PHYLO_XML_VERSION + "\n" );
1300         sb.append( "\n" );
1301         sb.append( "For more information: http://www.phylosoft.org/archaeopteryx/\n" );
1302         sb.append( "Email: " + Constants.AUTHOR_EMAIL + "\n\n" );
1303         TextFrame.instantiate( sb.toString() );
1304     }
1305
1306     static void setOvPlacementColorChooseMenuItem( final JMenuItem mi, final Options options ) {
1307         if ( ( options != null ) && ( options.getOvPlacement() != null ) ) {
1308             mi.setText( "Cycle Overview Placement... (current: " + options.getOvPlacement() + ")" );
1309         }
1310         else {
1311             mi.setText( "Cycle Overview Placement..." );
1312         }
1313     }
1314
1315     static void setCycleNodeFillMenuItem( final JMenuItem mi, final Options options ) {
1316         if ( ( options != null ) && ( options.getDefaultNodeFill() != null ) ) {
1317             mi.setText( "Cycle Node Shape Fill Type... (current: "
1318                     + options.getDefaultNodeFill().toString().toLowerCase() + ")" );
1319         }
1320         else {
1321             mi.setText( "Cycle Node Shape Fill Type..." );
1322         }
1323     }
1324
1325     static void setCycleNodeShapeMenuItem( final JMenuItem mi, final Options options ) {
1326         if ( ( options != null ) && ( options.getDefaultNodeShape() != null ) ) {
1327             mi.setText( "Cycle Node Shape Fill Type... (current: "
1328                     + options.getDefaultNodeShape().toString().toLowerCase() + ")" );
1329         }
1330         else {
1331             mi.setText( "Cycle Node Shape Fill Type..." );
1332         }
1333     }
1334
1335     static void setTextColorChooseMenuItem( final JMenuItem mi, final TreePanel tree_panel ) {
1336         if ( ( tree_panel != null ) && ( tree_panel.getTreeColorSet() != null ) ) {
1337             mi.setText( "Select Colors... (current: " + tree_panel.getTreeColorSet().getCurrentColorSchemeName() + ")" );
1338         }
1339         else {
1340             mi.setText( "Select Colors..." );
1341         }
1342     }
1343
1344     static void setTextForFontChooserMenuItem( final JMenuItem mi, final String font_desc ) {
1345         mi.setText( "Select Font... (current: " + font_desc + ")" );
1346     }
1347
1348     static void setTextMinSupportMenuItem( final JMenuItem mi, final Options options, final TreePanel current_tree_panel ) {
1349         if ( ( current_tree_panel == null ) || ( current_tree_panel.getPhylogeny() == null ) ) {
1350             mi.setEnabled( true );
1351         }
1352         else if ( AptxUtil.isHasAtLeastOneBranchWithSupportValues( current_tree_panel.getPhylogeny() ) ) {
1353             mi.setEnabled( true );
1354         }
1355         else {
1356             mi.setEnabled( false );
1357         }
1358         mi.setText( "Enter Min Confidence Value... (current: " + options.getMinConfidenceValue() + ")" );
1359     }
1360
1361     static void setTextNodeSizeMenuItem( final JMenuItem mi, final Options options ) {
1362         mi.setText( "Enter Default Node Shape Size... (current: " + options.getDefaultNodeShapeSize() + ")" );
1363     }
1364
1365     static void updateOptionsMenuDependingOnPhylogenyType( final MainPanel main_panel,
1366                                                            final JCheckBoxMenuItem scale,
1367                                                            final JCheckBoxMenuItem branch_lengths,
1368                                                            final JRadioButtonMenuItem non_lined_up,
1369                                                            final JRadioButtonMenuItem uniform_clado,
1370                                                            final JRadioButtonMenuItem nonuniform_clado,
1371                                                            final JCheckBoxMenuItem label_direction_cbmi ) {
1372         final TreePanel tree_panel = main_panel.getCurrentTreePanel();
1373         final ControlPanel control = main_panel.getControlPanel();
1374         final Options options = main_panel.getOptions();
1375         scale.setSelected( options.isShowScale() );
1376         branch_lengths.setSelected( options.isShowBranchLengthValues() );
1377         // non_lined_up.setSelected( options.isNonLinedUpCladogram() );
1378         if ( ( tree_panel != null ) && ( !tree_panel.isPhyHasBranchLengths() ) ) {
1379             scale.setSelected( false );
1380             scale.setEnabled( false );
1381             branch_lengths.setSelected( false );
1382             branch_lengths.setEnabled( false );
1383         }
1384         else if ( ( tree_panel != null ) && !control.isDrawPhylogram() ) {
1385             scale.setSelected( false );
1386             scale.setEnabled( false );
1387             branch_lengths.setEnabled( true );
1388         }
1389         else {
1390             scale.setEnabled( true );
1391             branch_lengths.setEnabled( true );
1392         }
1393         if ( ( tree_panel != null )
1394                 && ( ( tree_panel.getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.ROUNDED )
1395                         && ( tree_panel.getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE ) && ( tree_panel
1396                         .getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR ) ) ) {
1397             branch_lengths.setSelected( false );
1398             branch_lengths.setEnabled( false );
1399         }
1400         if ( tree_panel != null ) {
1401             if ( ( tree_panel.getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR )
1402                     || ( tree_panel.getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) ) {
1403                 non_lined_up.setEnabled( false );
1404                 uniform_clado.setEnabled( false );
1405                 nonuniform_clado.setEnabled( false );
1406             }
1407             else {
1408                 non_lined_up.setEnabled( true );
1409                 uniform_clado.setEnabled( true );
1410                 nonuniform_clado.setEnabled( true );
1411             }
1412         }
1413         else {
1414             if ( ( tree_panel != null )
1415                     && ( ( tree_panel.getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE ) && ( tree_panel
1416                             .getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR ) ) ) {
1417                 branch_lengths.setSelected( false );
1418                 branch_lengths.setEnabled( false );
1419             }
1420             if ( ( tree_panel != null )
1421                     && ( ( tree_panel.getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) || ( tree_panel
1422                             .getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) ) ) {
1423                 non_lined_up.setEnabled( false );
1424             }
1425             else {
1426                 // non_lined_up.setSelected( options.isNonLinedUpCladogram() );
1427                 non_lined_up.setEnabled( true );
1428             }
1429         }
1430         label_direction_cbmi.setEnabled( true );
1431         if ( tree_panel != null ) {
1432             if ( ( tree_panel.getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.UNROOTED )
1433                     && ( tree_panel.getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) ) {
1434                 label_direction_cbmi.setEnabled( false );
1435             }
1436             if ( tree_panel.getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) {
1437                 scale.setSelected( false );
1438                 scale.setEnabled( false );
1439             }
1440         }
1441     }
1442
1443     static void updateScreenTextAntialias( final List<TreePanel> treepanels ) {
1444         for( final TreePanel tree_panel : treepanels ) {
1445             tree_panel.setTextAntialias();
1446         }
1447     }
1448 }