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