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