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