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