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