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