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