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