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