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