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