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