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