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