1st fix of embedded applet null pointer "issue"... ^^
[jalview.git] / forester / java / src / org / forester / archaeopteryx / Configuration.java
1 // $Id:
2 // FORESTER -- software libraries and applications
3 // for evolutionary biology research and applications.
4 //
5 // Copyright (C) 2008-2009 Christian M. Zmasek
6 // Copyright (C) 2008-2009 Burnham Institute for Medical Research
7 // Copyright (C) 2000-2001 Washington University School of Medicine
8 // and Howard Hughes Medical Institute
9 // Copyright (C) 2003-2007 Ethalinda K.S. Cannon
10 // All rights reserved
11 //
12 // This library is free software; you can redistribute it and/or
13 // modify it under the terms of the GNU Lesser General Public
14 // License as published by the Free Software Foundation; either
15 // version 2.1 of the License, or (at your option) any later version.
16 //
17 // This library is distributed in the hope that it will be useful,
18 // but WITHOUT ANY WARRANTY; without even the implied warranty of
19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 // Lesser General Public License for more details.
21 //
22 // You should have received a copy of the GNU Lesser General Public
23 // License along with this library; if not, write to the Free Software
24 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
25 //
26 // Contact: phylosoft @ gmail . com
27 // WWW: www.phylosoft.org/forester
28
29 package org.forester.archaeopteryx;
30
31 import java.awt.Color;
32 import java.io.BufferedReader;
33 import java.io.File;
34 import java.io.FileReader;
35 import java.io.IOException;
36 import java.io.InputStreamReader;
37 import java.net.MalformedURLException;
38 import java.net.URL;
39 import java.util.Arrays;
40 import java.util.Hashtable;
41 import java.util.Map;
42 import java.util.SortedMap;
43 import java.util.StringTokenizer;
44 import java.util.TreeMap;
45
46 import org.forester.archaeopteryx.Options.CLADOGRAM_TYPE;
47 import org.forester.archaeopteryx.Options.NODE_LABEL_DIRECTION;
48 import org.forester.archaeopteryx.Options.OVERVIEW_PLACEMENT_TYPE;
49 import org.forester.archaeopteryx.Options.PHYLOGENY_GRAPHICS_TYPE;
50 import org.forester.phylogeny.data.NodeData.NODE_DATA;
51 import org.forester.phylogeny.data.NodeVisualization;
52 import org.forester.phylogeny.data.NodeVisualization.NodeFill;
53 import org.forester.phylogeny.data.NodeVisualization.NodeShape;
54 import org.forester.util.ForesterUtil;
55
56 public final class Configuration {
57
58     public enum EXT_NODE_DATA_RETURN_ON {
59         CONSOLE, WINODW;
60     }
61     static final String                     VALIDATE_AGAINST_PHYLOXML_XSD_SCHEMA                   = "validate_against_phyloxml_xsd_schema";
62     private static final String             WEB_LINK_KEY                                           = "web_link";
63     private static final String             DISPLAY_COLOR_KEY                                      = "display_color";
64     private static final int                DEPRECATED                                             = -2;
65     private UI                              _ui                                                    = UI.UNKNOWN;
66     private boolean                         _use_tabbed_display                                    = false;
67     private boolean                         _hide_controls_and_menus                               = false;
68     private CLADOGRAM_TYPE                  _cladogram_type                                        = Constants.CLADOGRAM_TYPE_DEFAULT;
69     private SortedMap<String, WebLink>      _weblinks                                              = null;
70     private SortedMap<String, Color>        _display_colors                                        = null;
71     private boolean                         _antialias_screen                                      = true;
72     private PHYLOGENY_GRAPHICS_TYPE         _phylogeny_graphics_type                               = PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR;
73     private String                          _base_font_family_name                                 = "";
74     private int                             _base_font_size                                        = -1;
75     private int                             _graphics_export_x                                     = -1;
76     private int                             _graphics_export_y                                     = -1;
77     private short                           _ov_max_width                                          = 80;
78     private short                           _ov_max_height                                         = 80;
79     private OVERVIEW_PLACEMENT_TYPE         _ov_placement                                          = OVERVIEW_PLACEMENT_TYPE.UPPER_LEFT;
80     private double                          _min_confidence_value                                  = Options.MIN_CONFIDENCE_DEFAULT;
81     private float                           _print_line_width                                      = Constants.PDF_LINE_WIDTH_DEFAULT;
82     private boolean                         _show_scale                                            = false;
83     private boolean                         _show_branch_length_values                             = false;
84     private boolean                         _show_overview                                         = true;
85     private short                           _number_of_digits_after_comma_for_confidence_values    = Constants.NUMBER_OF_DIGITS_AFTER_COMMA_FOR_CONFIDENCE_VALUES_DEFAULT;
86     private short                           _number_of_digits_after_comma_for_branch_length_values = Constants.NUMBER_OF_DIGITS_AFTER_COMMA_FOR_BRANCH_LENGTH_VALUES_DEFAULT;
87     private boolean                         _editable                                              = true;
88     private boolean                         _nh_parsing_replace_underscores                        = false;
89     private boolean                         _nh_parsing_extract_pfam_taxonomy_codes                = false;
90     private boolean                         _internal_number_are_confidence_for_nh_parsing         = false;
91     private boolean                         _display_sequence_relations                            = false;
92     private boolean                         _validate_against_phyloxml_xsd_schema                  = Constants.VALIDATE_AGAINST_PHYLOXML_XSD_SCJEMA_DEFAULT;
93     private boolean                         _background_color_gradient                             = false;
94     private boolean                         _show_domain_labels                                    = true;
95     private boolean                         _abbreviate_scientific_names                           = false;
96     private boolean                         _color_labels_same_as_parent_branch                    = false;
97     private boolean                         _show_default_node_shapes                              = false;
98     private NodeShape                       _default_node_shape                                    = NodeShape.CIRCLE;
99     private NodeFill                        _default_node_fill                                     = NodeFill.GRADIENT;
100     private short                           _default_node_shape_size                               = Constants.DEFAULT_NODE_SHAPE_SIZE_DEFAULT;
101     private boolean                         _taxonomy_colorize_node_shapes                         = false;
102     private int                             _default_bootstrap_samples                             = -1;
103     private File                            _path_to_local_mafft                                   = null;
104     private File                            _path_to_local_fastme                                  = null;
105     private File                            _path_to_local_raxml                                   = null;
106     private File                            _path_to_local_clustalo                                = null;
107     final static int                        display_as_phylogram                                   = 0;
108     final static int                        show_node_names                                        = 1;
109     final static int                        show_tax_code                                          = 2;
110     final static int                        show_annotation                                        = 3;
111     final static int                        write_confidence_values                                = 4;
112     final static int                        write_events                                           = 5;
113     final static int                        color_according_to_species                             = 6;
114     final static int                        color_branches                                         = 7;
115     final static int                        width_branches                                         = 8;
116     final static int                        show_custom_node_shapes                                = 9;
117     final static int                        show_domain_architectures                              = 10;
118     final static int                        show_binary_characters                                 = 11;
119     final static int                        show_binary_character_counts                           = 12;
120     final static int                        show_gene_names                                        = 13;
121     final static int                        show_sequence_acc                                      = 14;
122     final static int                        display_internal_data                                  = 15;
123     final static int                        dynamically_hide_data                                  = 16;
124     final static int                        show_taxonomy_scientific_names                         = 17;
125     final static int                        show_taxonomy_common_names                             = 18;
126     final static int                        color_according_to_annotation                          = 19;
127     final static int                        show_gene_symbols                                      = 20;
128     final static int                        node_data_popup                                        = 21;
129     final static int                        show_relation_confidence                               = 22;
130     final static int                        show_vector_data                                       = 23;
131     final static int                        show_taxonomy_images                                   = 24;
132     final static int                        show_properties                                        = 25;
133     // ------------------
134     // Click-to options
135     // ------------------
136     final static int                        display_node_data                                      = 0;
137     final static int                        collapse_uncollapse                                    = 1;
138     final static int                        reroot                                                 = 2;
139     final static int                        subtree                                                = 3;
140     final static int                        swap                                                   = 4;
141     final static int                        color_subtree                                          = 5;
142     final static int                        open_seq_web                                           = 6;
143     final static int                        open_tax_web                                           = 7;
144     final static int                        blast                                                  = 8;
145     final static int                        cut_subtree                                            = 9;
146     final static int                        copy_subtree                                           = 10;
147     final static int                        paste_subtree                                          = 11;
148     final static int                        delete_subtree_or_node                                 = 12;
149     final static int                        add_new_node                                           = 13;
150     final static int                        edit_node_data                                         = 14;
151     final static int                        sort_descendents                                       = 15;
152     final static int                        get_ext_desc_data                                      = 16;
153     // ---------------------------
154     // Display options for trees
155     // ---------------------------
156     // ---------------------------------
157     // Pertaining to the config itself
158     // ---------------------------------
159     // Full path to config (may be URL)
160     String                                  config_filename;
161     String                                  default_config_filename                                = Constants.DEFAULT_CONFIGURATION_FILE_NAME;
162     final static String                     display_options[][]                                    = {
163             { "Phylogram", "display", "?" }, { "Node Name", "display", "yes" }, { "Taxonomy Code", "display", "yes" },
164             { "Annotation", "nodisplay", "no" }, { "Confidence Values", "display", "?" }, { "Event", "display", "?" },
165             { "Taxonomy Colorize", "display", "no" }, { "Colorize Branches", "display", "no" },
166             { "Use Branch-Widths", "display", "no" }, { "Show Custom Nodes", "display", "yes" },
167             { "Domains", "nodisplay", "no" }, { "Binary Characters", "nodisplay", "no" },
168             { "Binary Char Counts", "nodisplay", "no" }, { "Prot/Gene Name", "display", "yes" },
169             { "Prot/Gene Acc", "display", "no" }, { "Show Internal Data", "display", "yes" },
170             { "Dyna Hide", "display", "yes" }, { "Taxonomy Scientific", "display", "yes" },
171             { "Taxonomy Common", "display", "no" }, { "Annotation Colorize", "nodisplay", "no" },
172             { "Prot/Gene Symbol", "display", "yes" }, { "Rollover", "display", "yes" },
173             { "Relation Confidence", "display", "no" }, { "Vector Data", "display", "no" },
174             { "Taxonomy Images", "display", "no" }, { "Properties", "display", "no" }             };
175     final static String                     clickto_options[][]                                    = {
176             { "Display Node Data", "display" }, { "Collapse/Uncollapse", "display" }, { "Root/Reroot", "display" },
177             { "Sub/Super Tree", "display" }, { "Swap Descendants", "display" }, { "Colorize Subtree", "display" },
178             { "Open Sequence Web", "display" }, { "Open Taxonomy Web", "display" }, { "Blast", "display" },
179             { "Cut Subtree", "display" }, { "Copy Subtree", "display" }, { "Paste Subtree", "display" },
180             { "Delete Subtree/Node", "display" }, { "Add New Node", "display" }, { "Edit Node Data", "display" },
181             { "Sort Descendants", "display" }, { "Return", "display" }                            };
182     // This option is selected in the dropdown
183     int                                     default_clickto                                        = Configuration.display_node_data;
184     // --------------
185     // Color set
186     // --------------
187     TreeColorSet                            tree_color_set;
188     // -------
189     // Fonts
190     // -------
191     TreeFontSet                             tree_font_set;
192     // ----------------
193     // Species colors
194     // ----------------
195     private static Hashtable<String, Color> _species_colors;
196     // ----------------
197     // Domain colors
198     // ----------------
199     private static Hashtable<String, Color> _domain_colors;
200     // ----------------
201     // Function colors
202     // ----------------
203     private static Hashtable<String, Color> _annotation_colors;
204     boolean                                 verbose                                                = Constants.VERBOSE_DEFAULT;
205     private NODE_LABEL_DIRECTION            _node_label_direction                                  = NODE_LABEL_DIRECTION.HORIZONTAL;
206     private Color                           _gui_background_color                                  = Constants.GUI_BACKGROUND_DEFAULT;
207     private Color                           _gui_checkbox_text_color                               = Constants.CHECKBOX_TEXT_COLOR_DEFAULT;
208     private Color                           _gui_checkbox_and_button_active_color                  = Constants.CHECKBOX_AND_BUTTON_ACTIVE_COLOR_DEFAULT;
209     private Color                           _gui_button_text_color                                 = Constants.BUTTON_TEXT_COLOR_DEFAULT;
210     private Color                           _gui_button_background_color                           = Constants.BUTTON_BACKGROUND_COLOR_DEFAULT;
211     private Color                           _gui_menu_background_color                             = Constants.MENU_BACKGROUND_COLOR_DEFAULT;
212     private Color                           _gui_menu_text_color                                   = Constants.MENU_TEXT_COLOR_DEFAULT;
213     private Color                           _gui_button_border_color                               = Constants.BUTTON_BORDER_COLOR_DEFAULT;
214     private Color                           _domain_structure_font_color                           = Constants.DOMAIN_STRUCTURE_FONT_COLOR_DEFAULT;
215     private Color                           _domain_structure_base_color                           = Constants.DOMAIN_STRUCTURE_BASE_COLOR_DEFAULT;
216     private NODE_DATA                       _ext_desc_data_to_return                               = NODE_DATA.NODE_NAME;
217     private String                          _label_for_get_ext_descendents_data                    = "";
218     private EXT_NODE_DATA_RETURN_ON         _ext_node_data_return_on                               = EXT_NODE_DATA_RETURN_ON.WINODW;
219     private static String                   DEFAULT_FONT_FAMILY                                    = "";
220     static {
221         for( final String font_name : Constants.DEFAULT_FONT_CHOICES ) {
222             if ( Arrays.binarySearch( AptxUtil.getAvailableFontFamiliesSorted(), font_name ) >= 0 ) {
223                 DEFAULT_FONT_FAMILY = font_name;
224                 break;
225             }
226         }
227         if ( ForesterUtil.isEmpty( DEFAULT_FONT_FAMILY ) ) {
228             DEFAULT_FONT_FAMILY = Constants.DEFAULT_FONT_CHOICES[ Constants.DEFAULT_FONT_CHOICES.length - 1 ];
229         }
230     }
231
232     public Configuration() {
233         this( null, false, false, false );
234     }
235
236     public Configuration( final String cf, final boolean is_url, final boolean is_applet, final boolean verbose ) {
237         if ( ForesterUtil.isEmpty( cf ) ) {
238             config_filename = default_config_filename;
239         }
240         else {
241             config_filename = cf;
242         }
243         setWebLinks( new TreeMap<String, WebLink>() );
244         setDisplayColors( new TreeMap<String, Color>() );
245         config_filename = config_filename.trim();
246         URL u = null;
247         if ( is_url ) {
248             // If URL, open accordingly
249             try {
250                 u = new URL( config_filename );
251                 try {
252                     final InputStreamReader isr = new InputStreamReader( u.openStream() );
253                     final BufferedReader bf = new BufferedReader( isr );
254                     readConfig( bf );
255                     bf.close();
256                     ForesterUtil.programMessage( Constants.PRG_NAME, "successfully read from configuration url ["
257                             + config_filename + "]" );
258                 }
259                 catch ( final Exception e ) {
260                     ForesterUtil.printWarningMessage( Constants.PRG_NAME, "failed to read configuration from ["
261                             + config_filename + "]: " + e.getLocalizedMessage() );
262                 }
263             }
264             catch ( final Exception e ) {
265                 ForesterUtil.printWarningMessage( Constants.PRG_NAME, "cannot find or open configuration url ["
266                         + config_filename + "]" );
267             }
268         }
269         else {
270             // Otherwise, open as a file
271             File f = new File( config_filename );
272             if ( !f.exists() ) {
273                 f = new File( config_filename + ".txt" );
274             }
275             if ( f.exists() && f.canRead() ) {
276                 try {
277                     final BufferedReader bf = new BufferedReader( new FileReader( f ) );
278                     readConfig( bf );
279                     bf.close();
280                 }
281                 catch ( final Exception e ) {
282                     if ( verbose ) {
283                         ForesterUtil.printWarningMessage( Constants.PRG_NAME, "failed to read configuration from ["
284                                 + config_filename + "]: " + e );
285                     }
286                 }
287             }
288             else {
289                 if ( verbose ) {
290                     ForesterUtil.printWarningMessage( Constants.PRG_NAME, "cannot find or open configuration file ["
291                             + config_filename + "]" );
292                 }
293             }
294         }
295     }
296
297     private void createWebLink( final String url_str, final String desc, final String source_identifier ) {
298         WebLink weblink = null;
299         boolean ex = false;
300         try {
301             weblink = new WebLink( new URL( url_str.trim() ), desc.trim(), source_identifier.trim() );
302         }
303         catch ( final MalformedURLException e ) {
304             ForesterUtil.printWarningMessage( Constants.PRG_NAME, "could not create URL from [" + url_str + "]" );
305             ex = true;
306         }
307         if ( !ex && ( weblink != null ) ) {
308             getWebLinks().put( weblink.getSourceIdentifier().toLowerCase(), weblink );
309         }
310     }
311
312     boolean displaySequenceRelations() {
313         return _display_sequence_relations;
314     }
315
316     boolean doCheckOption( final int which ) {
317         return ( display_options[ which ][ 2 ].equalsIgnoreCase( "yes" ) )
318                 || ( display_options[ which ][ 2 ].equalsIgnoreCase( "true" ) );
319     }
320
321     boolean doDisplayClickToOption( final int which ) {
322         return clickto_options[ which ][ 1 ].equalsIgnoreCase( "display" );
323     }
324
325     boolean doDisplayOption( final int which ) {
326         return display_options[ which ][ 1 ].equalsIgnoreCase( "display" );
327     }
328
329     /**
330      * Will attempt to use the phylogeny to determine whether to check
331      * this or not (e.g. phylogram)
332      * 
333      */
334     boolean doGuessCheckOption( final int which ) {
335         return display_options[ which ][ 2 ].equals( "?" );
336     }
337
338     Map<String, Color> getAnnotationColors() {
339         if ( _annotation_colors == null ) {
340             _annotation_colors = new Hashtable<String, Color>();
341         }
342         return _annotation_colors;
343     }
344
345     public String getBaseFontFamilyName() {
346         return _base_font_family_name;
347     }
348
349     int getBaseFontSize() {
350         return _base_font_size;
351     }
352
353     CLADOGRAM_TYPE getCladogramType() {
354         return _cladogram_type;
355     }
356
357     private int getClickToIndex( final String name ) {
358         int index = -1;
359         if ( name.equals( "edit_info" ) ) {
360             index = Configuration.display_node_data;
361             ForesterUtil
362                     .printWarningMessage( Constants.PRG_NAME,
363                                           "configuration key [edit_info] is deprecated, use [display node data] instead" );
364         }
365         else if ( name.equals( "display_node_data" ) ) {
366             index = Configuration.display_node_data;
367         }
368         else if ( name.equals( "collapse_uncollapse" ) ) {
369             index = Configuration.collapse_uncollapse;
370         }
371         else if ( name.equals( "reroot" ) ) {
372             index = Configuration.reroot;
373         }
374         else if ( name.equals( "subtree" ) ) {
375             index = Configuration.subtree;
376         }
377         else if ( name.equals( "swap" ) ) {
378             index = Configuration.swap;
379         }
380         else if ( name.equals( "sort_descendants" ) ) {
381             index = Configuration.sort_descendents;
382         }
383         else if ( name.equals( "get_ext_descendents_data" ) ) {
384             index = Configuration.get_ext_desc_data;
385         }
386         else if ( name.equals( "display_sequences" ) ) {
387             ForesterUtil
388                     .printWarningMessage( Constants.PRG_NAME, "configuration key [display_sequences] is deprecated" );
389             return DEPRECATED;
390         }
391         else if ( name.equals( "open_seq_web" ) ) {
392             index = Configuration.open_seq_web;
393         }
394         else if ( name.equals( "open_tax_web" ) ) {
395             index = Configuration.open_tax_web;
396         }
397         else if ( name.equals( "blast" ) ) {
398             index = Configuration.blast;
399         }
400         else if ( name.equals( "cut_subtree" ) ) {
401             index = Configuration.cut_subtree;
402         }
403         else if ( name.equals( "copy_subtree" ) ) {
404             index = Configuration.copy_subtree;
405         }
406         else if ( name.equals( "paste_subtree" ) ) {
407             index = Configuration.paste_subtree;
408         }
409         else if ( name.equals( "delete" ) ) {
410             index = Configuration.delete_subtree_or_node;
411         }
412         else if ( name.equals( "add_new_node" ) ) {
413             index = Configuration.add_new_node;
414         }
415         else if ( name.equals( "edit_node_data" ) ) {
416             index = Configuration.edit_node_data;
417         }
418         else if ( name.equals( "display_node_popup" ) ) {
419             ForesterUtil.printWarningMessage( Constants.PRG_NAME,
420                                               "configuration key [display_node_popup] is deprecated" );
421             return DEPRECATED;
422         }
423         else if ( name.equals( "custom_option" ) ) {
424             ForesterUtil.printWarningMessage( Constants.PRG_NAME, "configuration key [custom_option] is deprecated" );
425             return DEPRECATED;
426         }
427         else if ( name.equals( "color_subtree" ) ) {
428             index = Configuration.color_subtree;
429         }
430         else if ( name.equals( "go_to_swiss_prot" ) ) {
431             ForesterUtil.printWarningMessage( Constants.PRG_NAME, "configuration key [go_to_swiss_prot] is deprecated" );
432             return DEPRECATED;
433         }
434         return index;
435     }
436
437     int getClickToOptionsCount() {
438         return clickto_options.length;
439     }
440
441     String getClickToTitle( final int which ) {
442         return clickto_options[ which ][ 0 ];
443     }
444
445     public int getDefaultBootstrapSamples() {
446         return _default_bootstrap_samples;
447     }
448
449     public File getpathToLocalMafft() {
450         return _path_to_local_mafft;
451     }
452
453     public File getPathToLocalFastme() {
454         return _path_to_local_fastme;
455     }
456
457     public File getPathToLocalRaxml() {
458         return _path_to_local_raxml;
459     }
460
461     int getDefaultDisplayClicktoOption() {
462         return default_clickto;
463     }
464
465     public NodeFill getDefaultNodeFill() {
466         return _default_node_fill;
467     }
468
469     public NodeShape getDefaultNodeShape() {
470         return _default_node_shape;
471     }
472
473     public short getDefaultNodeShapeSize() {
474         return _default_node_shape_size;
475     }
476
477     SortedMap<String, Color> getDisplayColors() {
478         return _display_colors;
479     }
480
481     String getDisplayTitle( final int which ) {
482         return display_options[ which ][ 0 ];
483     }
484
485     Map<String, Color> getDomainColors() {
486         if ( _domain_colors == null ) {
487             _domain_colors = new Hashtable<String, Color>();
488         }
489         return _domain_colors;
490     }
491
492     public Color getDomainStructureBaseColor() {
493         return _domain_structure_base_color;
494     }
495
496     public Color getDomainStructureFontColor() {
497         return _domain_structure_font_color;
498     }
499
500     int getGraphicsExportX() {
501         return _graphics_export_x;
502     }
503
504     int getGraphicsExportY() {
505         return _graphics_export_y;
506     }
507
508     Color getGuiBackgroundColor() {
509         return _gui_background_color;
510     }
511
512     Color getGuiButtonBackgroundColor() {
513         return _gui_button_background_color;
514     }
515
516     Color getGuiButtonBorderColor() {
517         return _gui_button_border_color;
518     }
519
520     Color getGuiButtonTextColor() {
521         return _gui_button_text_color;
522     }
523
524     Color getGuiCheckboxAndButtonActiveColor() {
525         return _gui_checkbox_and_button_active_color;
526     }
527
528     Color getGuiCheckboxTextColor() {
529         return _gui_checkbox_text_color;
530     }
531
532     Color getGuiMenuBackgroundColor() {
533         return _gui_menu_background_color;
534     }
535
536     Color getGuiMenuTextColor() {
537         return _gui_menu_text_color;
538     }
539
540     double getMinConfidenceValue() {
541         return _min_confidence_value;
542     }
543
544     NODE_LABEL_DIRECTION getNodeLabelDirection() {
545         return _node_label_direction;
546     }
547
548     short getNumberOfDigitsAfterCommaForBranchLengthValues() {
549         return _number_of_digits_after_comma_for_branch_length_values;
550     }
551
552     short getNumberOfDigitsAfterCommaForConfidenceValues() {
553         return _number_of_digits_after_comma_for_confidence_values;
554     }
555
556     short getOvMaxHeight() {
557         return _ov_max_height;
558     }
559
560     short getOvMaxWidth() {
561         return _ov_max_width;
562     }
563
564     OVERVIEW_PLACEMENT_TYPE getOvPlacement() {
565         return _ov_placement;
566     }
567
568     PHYLOGENY_GRAPHICS_TYPE getPhylogenyGraphicsType() {
569         return _phylogeny_graphics_type;
570     }
571
572     float getPrintLineWidth() {
573         return _print_line_width;
574     }
575
576     Hashtable<String, Color> getSpeciesColors() {
577         if ( _species_colors == null ) {
578             _species_colors = new Hashtable<String, Color>();
579         }
580         return _species_colors;
581     }
582
583     TreeColorSet getTreeColorSet() {
584         return null;
585     }
586
587     TreeFontSet getTreeFontSet() {
588         return null;
589     }
590
591     WebLink getWebLink( final String source ) {
592         return getWebLinks().get( source );
593     }
594
595     Map<String, WebLink> getWebLinks() {
596         return _weblinks;
597     }
598
599     public boolean isAbbreviateScientificTaxonNames() {
600         return _abbreviate_scientific_names;
601     }
602
603     boolean isAntialiasScreen() {
604         return _antialias_screen;
605     }
606
607     public boolean isBackgroundColorGradient() {
608         return _background_color_gradient;
609     }
610
611     public boolean isColorLabelsSameAsParentBranch() {
612         return _color_labels_same_as_parent_branch;
613     }
614
615     /**
616      * Convenience method.
617      * 
618      * @return true if value in configuration file was 'yes'
619      */
620     boolean isDrawAsPhylogram() {
621         return doCheckOption( display_as_phylogram );
622     }
623
624     boolean isEditable() {
625         return _editable;
626     }
627
628     boolean isExtractPfamTaxonomyCodesInNhParsing() {
629         return _nh_parsing_extract_pfam_taxonomy_codes;
630     }
631
632     boolean isHasWebLink( final String source ) {
633         return getWebLinks().containsKey( source );
634     }
635
636     /**
637      * Only used by ArchaeoptryxE.
638      *
639      */
640     boolean isHideControlPanelAndMenubar() {
641         return _hide_controls_and_menus;
642     }
643
644     boolean isInternalNumberAreConfidenceForNhParsing() {
645         return _internal_number_are_confidence_for_nh_parsing;
646     }
647
648     boolean isReplaceUnderscoresInNhParsing() {
649         return _nh_parsing_replace_underscores;
650     }
651
652     boolean isShowBranchLengthValues() {
653         return _show_branch_length_values;
654     }
655
656     public boolean isShowDefaultNodeShapes() {
657         return _show_default_node_shapes;
658     }
659
660     public boolean isShowDomainLabels() {
661         return _show_domain_labels;
662     }
663
664     boolean isShowOverview() {
665         return _show_overview;
666     }
667
668     boolean isShowScale() {
669         return _show_scale;
670     }
671
672     public boolean isTaxonomyColorizeNodeShapes() {
673         return _taxonomy_colorize_node_shapes;
674     }
675
676     final boolean isUseNativeUI() {
677         if ( ( _ui == UI.UNKNOWN ) && AptxUtil.isMac() && AptxUtil.isJava15() ) {
678             _ui = UI.NATIVE;
679         }
680         return _ui == UI.NATIVE;
681     }
682
683     /**
684      * Only used by ArchaeoptryxE.
685      *
686      */
687     boolean isUseTabbedDisplay() {
688         return _use_tabbed_display;
689     }
690
691     boolean isValidatePhyloXmlAgainstSchema() {
692         return _validate_against_phyloxml_xsd_schema;
693     }
694
695     private boolean parseBoolean( final String str ) {
696         final String my_str = str.trim().toLowerCase();
697         if ( my_str.equals( "yes" ) || my_str.equals( "true" ) ) {
698             return true;
699         }
700         else if ( my_str.equals( "no" ) || my_str.equals( "false" ) ) {
701             return false;
702         }
703         else {
704             ForesterUtil.printWarningMessage( Constants.PRG_NAME, "could not parse boolean value from [" + str + "]" );
705             return false;
706         }
707     }
708
709     private double parseDouble( final String str ) {
710         double d = 0.0;
711         try {
712             d = Double.parseDouble( str.trim() );
713         }
714         catch ( final Exception e ) {
715             ForesterUtil.printWarningMessage( Constants.PRG_NAME, "could not parse double from [" + str + "]" );
716             d = 0.0;
717         }
718         return d;
719     }
720
721     private float parseFloat( final String str ) {
722         float f = 0.0f;
723         try {
724             f = Float.parseFloat( str.trim() );
725         }
726         catch ( final Exception e ) {
727             ForesterUtil.printWarningMessage( Constants.PRG_NAME, "could not parse float from [" + str + "]" );
728             f = 0.0f;
729         }
730         return f;
731     }
732
733     private int parseInt( final String str ) {
734         int i = -1;
735         try {
736             i = Integer.parseInt( str.trim() );
737         }
738         catch ( final Exception e ) {
739             ForesterUtil.printWarningMessage( Constants.PRG_NAME, "could not parse integer from [" + str + "]" );
740             i = -1;
741         }
742         return i;
743     }
744
745     private short parseShort( final String str ) {
746         short i = -1;
747         try {
748             i = Short.parseShort( str.trim() );
749         }
750         catch ( final Exception e ) {
751             ForesterUtil.printWarningMessage( Constants.PRG_NAME, "could not parse short from [" + str + "]" );
752             i = -1;
753         }
754         return i;
755     }
756
757     private void processFontFamily( final StringTokenizer st ) {
758         setBaseFontFamilyName( "" );
759         final String font_str = ( ( String ) st.nextElement() ).trim();
760         final String[] fonts = font_str.split( ",+" );
761         for( String font : fonts ) {
762             font = font.replace( '_', ' ' ).trim();
763             if ( Arrays.binarySearch( AptxUtil.getAvailableFontFamiliesSorted(), font ) >= 0 ) {
764                 setBaseFontFamilyName( font );
765                 break;
766             }
767         }
768     }
769
770     public void putDisplayColors( final String key, final Color color ) {
771         getDisplayColors().put( key, color );
772     }
773
774     /**
775      * read each line of config file, process non-comment lines
776      * @throws IOException 
777      */
778     private void readConfig( final BufferedReader conf_in ) throws IOException {
779         String line;
780         do {
781             line = conf_in.readLine();
782             if ( line != null ) {
783                 line = line.trim();
784                 // skip comments and blank lines
785                 if ( !line.startsWith( "#" ) && ( !ForesterUtil.isEmpty( line ) ) ) {
786                     // convert runs of spaces to tabs
787                     line = line.replaceAll( "\\s+", "\t" );
788                     final StringTokenizer st = new StringTokenizer( line, "\t" );
789                     setKeyValue( st );
790                 }
791             }
792         } while ( line != null );
793     }
794
795     public void setAbbreviateScientificTaxonNames( final boolean abbreviate_scientific_names ) {
796         _abbreviate_scientific_names = abbreviate_scientific_names;
797     }
798
799     private void setAntialiasScreen( final boolean antialias_screen ) {
800         _antialias_screen = antialias_screen;
801     }
802
803     public void setBackgroundColorGradient( final boolean background_color_gradient ) {
804         _background_color_gradient = background_color_gradient;
805     }
806
807     public void setBaseFontFamilyName( final String base_font_family_name ) {
808         _base_font_family_name = base_font_family_name;
809     }
810
811     public void setBaseFontSize( final int base_font_size ) {
812         _base_font_size = base_font_size;
813     }
814
815     private void setCladogramType( final CLADOGRAM_TYPE cladogram_type ) {
816         _cladogram_type = cladogram_type;
817     }
818
819     public void setColorizeBranches( final boolean b ) {
820         display_options[ color_branches ][ 2 ] = b ? "yes" : "no";
821     }
822
823     public void setColorLabelsSameAsParentBranch( final boolean color_labels_same_as_parent_branch ) {
824         _color_labels_same_as_parent_branch = color_labels_same_as_parent_branch;
825     }
826
827     private void setDefaultBootstrapSamples( final int default_bootstrap_samples ) {
828         _default_bootstrap_samples = default_bootstrap_samples;
829     }
830
831     private void setPathToLocalMafft( final File path_to_local_mafft ) {
832         _path_to_local_mafft = path_to_local_mafft;
833     }
834
835     private void setPathToLocalFastme( final File path_to_local_fastme ) {
836         _path_to_local_fastme = path_to_local_fastme;
837     }
838
839     private void setPathToLocalRaxml( final File path_to_local_raxml ) {
840         _path_to_local_raxml = path_to_local_raxml;
841     }
842
843     public File getPathToLocalClustalOmega() {
844         return _path_to_local_clustalo;
845     }
846
847     public void setPathToLocalClustalOmega( final File path_to_local_clustalo ) {
848         _path_to_local_clustalo = path_to_local_clustalo;
849     }
850
851     public void setDefaultNodeFill( final NodeFill default_node_fill ) {
852         _default_node_fill = default_node_fill;
853     }
854
855     public void setDefaultNodeShape( final NodeShape default_node_shape ) {
856         _default_node_shape = default_node_shape;
857     }
858
859     public void setDefaultNodeShapeSize( final short default_node_shape_size ) {
860         _default_node_shape_size = default_node_shape_size;
861     }
862
863     public void setDisplayAsPhylogram( final boolean b ) {
864         display_options[ display_as_phylogram ][ 2 ] = b ? "yes" : "no";
865     }
866
867     public void setDisplayColors( final SortedMap<String, Color> display_colors ) {
868         _display_colors = display_colors;
869     }
870
871     public void setDisplayConfidenceValues( final boolean b ) {
872         display_options[ write_confidence_values ][ 2 ] = b ? "yes" : "no";
873     }
874
875     public void setDisplayInternalData( final boolean b ) {
876         display_options[ display_internal_data ][ 2 ] = b ? "yes" : "no";
877     }
878
879     public void setDisplayNodeNames( final boolean b ) {
880         display_options[ show_node_names ][ 2 ] = b ? "yes" : "no";
881     }
882
883     public void setDisplaySequenceAcc( final boolean b ) {
884         display_options[ show_sequence_acc ][ 2 ] = b ? "yes" : "no";
885     }
886
887     public void setDisplaySequenceNames( final boolean b ) {
888         display_options[ show_gene_names ][ 2 ] = b ? "yes" : "no";
889     }
890
891     public void setDisplaySequenceRelations( final boolean display_sequence_relations ) {
892         _display_sequence_relations = display_sequence_relations;
893     }
894
895     public void setDisplaySequenceSymbols( final boolean b ) {
896         display_options[ show_gene_symbols ][ 2 ] = b ? "yes" : "no";
897     }
898
899     public void setDisplayTaxonomyCode( final boolean b ) {
900         display_options[ show_tax_code ][ 2 ] = b ? "yes" : "no";
901     }
902
903     public void setDisplayTaxonomyCommonNames( final boolean b ) {
904         display_options[ show_taxonomy_common_names ][ 2 ] = b ? "yes" : "no";
905     }
906
907     public void setDisplayTaxonomyImages( final boolean b ) {
908         display_options[ show_taxonomy_images ][ 2 ] = b ? "yes" : "no";
909     }
910
911     public void setDisplayTaxonomyScientificNames( final boolean b ) {
912         display_options[ show_taxonomy_scientific_names ][ 2 ] = b ? "yes" : "no";
913     }
914
915     public void setDynamicallyHideData( final boolean b ) {
916         display_options[ dynamically_hide_data ][ 2 ] = b ? "yes" : "no";
917     }
918
919     private void setEditable( final boolean editable ) {
920         _editable = editable;
921     }
922
923     public void setExtractPfamTaxonomyCodesInNhParsing( final boolean nh_parsing_extract_pfam_taxonomy_codes ) {
924         _nh_parsing_extract_pfam_taxonomy_codes = nh_parsing_extract_pfam_taxonomy_codes;
925     }
926
927     private void setGraphicsExportX( final int graphics_export_x ) {
928         _graphics_export_x = graphics_export_x;
929     }
930
931     private void setGraphicsExportY( final int graphics_export_y ) {
932         _graphics_export_y = graphics_export_y;
933     }
934
935     private void setInternalNumberAreConfidenceForNhParsing( final boolean internal_number_are_confidence_for_nh_parsing ) {
936         _internal_number_are_confidence_for_nh_parsing = internal_number_are_confidence_for_nh_parsing;
937     }
938
939     /**
940      * Set a key-value(s) tuple
941      */
942     private void setKeyValue( final StringTokenizer st ) {
943         final String key = ( ( String ) st.nextElement() ).replace( ':', ' ' ).trim().toLowerCase();
944         if ( !st.hasMoreElements() ) {
945             return;
946         }
947         // Handle single value settings first:
948         if ( key.equals( "default_click_to" ) ) {
949             final String clickto_name = ( String ) st.nextElement();
950             default_clickto = getClickToIndex( clickto_name );
951             if ( default_clickto == -1 ) {
952                 ForesterUtil.printWarningMessage( Constants.PRG_NAME, "invalid value [" + clickto_name
953                         + "] for [default_click_to]" );
954                 default_clickto = 0;
955             }
956             else if ( default_clickto == DEPRECATED ) {
957                 // Deprecated.
958             }
959         }
960         else if ( key.equals( "native_ui" ) ) {
961             final String my_str = ( ( String ) st.nextElement() ).trim().toLowerCase();
962             if ( my_str.equals( "yes" ) || my_str.equals( "true" ) ) {
963                 _ui = UI.NATIVE;
964             }
965             else if ( my_str.equals( "no" ) || my_str.equals( "false" ) ) {
966                 _ui = UI.CROSSPLATFORM;
967             }
968             else if ( my_str.equals( "?" ) ) {
969                 _ui = UI.UNKNOWN;
970             }
971             else {
972                 ForesterUtil.printWarningMessage( Constants.PRG_NAME, "could not parse yes/no/? value from [" + my_str
973                         + "]" );
974                 _ui = UI.UNKNOWN;
975             }
976         }
977         else if ( key.equals( VALIDATE_AGAINST_PHYLOXML_XSD_SCHEMA ) ) {
978             setValidatePhyloXmlAgainstSchema( parseBoolean( ( String ) st.nextElement() ) );
979         }
980         else if ( key.equals( "antialias_screen" ) ) {
981             setAntialiasScreen( parseBoolean( ( String ) st.nextElement() ) );
982         }
983         else if ( key.equals( "phylogeny_graphics_type" ) ) {
984             final String type_str = ( ( String ) st.nextElement() ).trim();
985             if ( type_str.equalsIgnoreCase( PHYLOGENY_GRAPHICS_TYPE.CONVEX.toString() ) ) {
986                 setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CONVEX );
987             }
988             else if ( type_str.equalsIgnoreCase( PHYLOGENY_GRAPHICS_TYPE.CURVED.toString() ) ) {
989                 setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CURVED );
990             }
991             else if ( type_str.equalsIgnoreCase( PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE.toString() ) ) {
992                 setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE );
993             }
994             else if ( type_str.equalsIgnoreCase( PHYLOGENY_GRAPHICS_TYPE.ROUNDED.toString() ) ) {
995                 setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.ROUNDED );
996             }
997             else if ( type_str.equalsIgnoreCase( PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR.toString() ) ) {
998                 setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR );
999             }
1000             else if ( type_str.equalsIgnoreCase( PHYLOGENY_GRAPHICS_TYPE.TRIANGULAR.toString() ) ) {
1001                 setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.TRIANGULAR );
1002             }
1003             else if ( type_str.equalsIgnoreCase( PHYLOGENY_GRAPHICS_TYPE.UNROOTED.toString() ) ) {
1004                 setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.UNROOTED );
1005             }
1006             else if ( type_str.equalsIgnoreCase( PHYLOGENY_GRAPHICS_TYPE.CIRCULAR.toString() ) ) {
1007                 setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CIRCULAR );
1008             }
1009             else {
1010                 setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR );
1011                 ForesterUtil.printWarningMessage( Constants.PRG_NAME, "unknown value [" + type_str
1012                         + "] for [phylogeny_graphics_type]" );
1013             }
1014         }
1015         else if ( key.equals( "min_confidence_value" ) ) {
1016             final String mcv_str = ( ( String ) st.nextElement() ).trim();
1017             final double d = parseDouble( mcv_str );
1018             setMinConfidenceValue( d );
1019         }
1020         else if ( key.equals( "font_family" ) ) {
1021             processFontFamily( st );
1022         }
1023         else if ( key.equals( "font_size" ) ) {
1024             final String size_str = ( ( String ) st.nextElement() ).trim();
1025             final int i = parseInt( size_str );
1026             setBaseFontSize( i );
1027         }
1028         else if ( key.equals( "graphics_export_x" ) ) {
1029             final String str = ( ( String ) st.nextElement() ).trim();
1030             final int i = parseInt( str );
1031             setGraphicsExportX( i );
1032         }
1033         else if ( key.equals( "graphics_export_y" ) ) {
1034             final String str = ( ( String ) st.nextElement() ).trim();
1035             final int i = parseInt( str );
1036             setGraphicsExportY( i );
1037         }
1038         else if ( key.equals( "pdf_export_line_width" ) ) {
1039             final String str = ( ( String ) st.nextElement() ).trim();
1040             final float f = parseFloat( str );
1041             if ( f > 0 ) {
1042                 setPrintLineWidth( f );
1043             }
1044             else {
1045                 ForesterUtil.printWarningMessage( Constants.PRG_NAME,
1046                                                   "value for [pdf_export_line_width] cannot be zero or negative" );
1047             }
1048         }
1049         else if ( key.equals( "default_number_of_bootstrap_resamples" ) ) {
1050             final String str = ( ( String ) st.nextElement() ).trim();
1051             final int i = parseInt( str );
1052             if ( i >= 0 ) {
1053                 setDefaultBootstrapSamples( i );
1054             }
1055             else {
1056                 ForesterUtil
1057                         .printWarningMessage( Constants.PRG_NAME,
1058                                               "value for [default_number_of_bootstrap_resamples] cannot be negative" );
1059             }
1060         }
1061         else if ( key.equals( "clustalo_local" ) ) {
1062             final String str = ( ( String ) st.nextElement() ).trim();
1063             if ( !ForesterUtil.isEmpty( str ) ) {
1064                 setPathToLocalClustalOmega( new File( str ) );
1065             }
1066         }
1067         else if ( key.equals( "mafft_local" ) ) {
1068             final String str = ( ( String ) st.nextElement() ).trim();
1069             if ( !ForesterUtil.isEmpty( str ) ) {
1070                 setPathToLocalMafft( new File( str ) );
1071             }
1072         }
1073         else if ( key.equals( "fastme_local" ) ) {
1074             final String str = ( ( String ) st.nextElement() ).trim();
1075             if ( !ForesterUtil.isEmpty( str ) ) {
1076                 setPathToLocalFastme( new File( str ) );
1077             }
1078         }
1079         else if ( key.equals( "raxml_local" ) ) {
1080             final String str = ( ( String ) st.nextElement() ).trim();
1081             if ( !ForesterUtil.isEmpty( str ) ) {
1082                 setPathToLocalRaxml( new File( str ) );
1083             }
1084         }
1085         else if ( key.equals( "show_scale" ) ) {
1086             setShowScale( parseBoolean( ( String ) st.nextElement() ) );
1087         }
1088         else if ( key.equals( "show_overview" ) ) {
1089             setShowOverview( parseBoolean( ( String ) st.nextElement() ) );
1090         }
1091         else if ( key.equals( "show_branch_length_values" ) ) {
1092             setShowBranchLengthValues( parseBoolean( ( String ) st.nextElement() ) );
1093         }
1094         else if ( key.equals( "background_gradient" ) ) {
1095             setBackgroundColorGradient( parseBoolean( ( String ) st.nextElement() ) );
1096         }
1097         else if ( key.equals( "color_labels_same_as_branch_length_values" ) ) {
1098             setColorLabelsSameAsParentBranch( parseBoolean( ( String ) st.nextElement() ) );
1099         }
1100         else if ( key.equals( "show_domain_labels" ) ) {
1101             setShowDomainLabels( parseBoolean( ( String ) st.nextElement() ) );
1102         }
1103         else if ( key.equals( "abbreviate_scientific_names" ) ) {
1104             setAbbreviateScientificTaxonNames( parseBoolean( ( String ) st.nextElement() ) );
1105         }
1106         else if ( key.equals( "cladogram_type" ) ) {
1107             final String type_str = ( ( String ) st.nextElement() ).trim();
1108             if ( type_str.equalsIgnoreCase( Options.CLADOGRAM_TYPE.NON_LINED_UP.toString() ) ) {
1109                 setCladogramType( Options.CLADOGRAM_TYPE.NON_LINED_UP );
1110             }
1111             else if ( type_str.equalsIgnoreCase( Options.CLADOGRAM_TYPE.EXT_NODE_SUM_DEP.toString() ) ) {
1112                 setCladogramType( Options.CLADOGRAM_TYPE.EXT_NODE_SUM_DEP );
1113             }
1114             else if ( type_str.equalsIgnoreCase( Options.CLADOGRAM_TYPE.TOTAL_NODE_SUM_DEP.toString() ) ) {
1115                 setCladogramType( Options.CLADOGRAM_TYPE.TOTAL_NODE_SUM_DEP );
1116             }
1117             else {
1118                 ForesterUtil.printWarningMessage( Constants.PRG_NAME, "unknown value [" + type_str
1119                         + "] for [cladogram_type]" );
1120             }
1121         }
1122         else if ( key.equals( "non_lined_up_cladogram" ) ) {
1123             ForesterUtil
1124                     .printWarningMessage( Constants.PRG_NAME,
1125                                           "configuration key [non_lined_up_cladogram] is deprecated, use [cladogram_type] instead" );
1126         }
1127         else if ( key.equals( "hide_controls_and_menus" ) ) {
1128             _hide_controls_and_menus = parseBoolean( ( String ) st.nextElement() );
1129         }
1130         else if ( key.equals( "use_tabbed_display" ) ) {
1131             _use_tabbed_display = parseBoolean( ( String ) st.nextElement() );
1132         }
1133         else if ( key.equals( "overview_width" ) ) {
1134             final short i = parseShort( ( ( String ) st.nextElement() ) );
1135             setOvMaxWidth( i );
1136         }
1137         else if ( key.equals( "overview_height" ) ) {
1138             final short i = parseShort( ( ( String ) st.nextElement() ) );
1139             setOvMaxHeight( i );
1140         }
1141         else if ( key.equals( "overview_placement_type" ) ) {
1142             final String type_str = ( ( String ) st.nextElement() ).trim();
1143             if ( type_str.equalsIgnoreCase( OVERVIEW_PLACEMENT_TYPE.UPPER_LEFT.toTag() ) ) {
1144                 setOvPlacement( OVERVIEW_PLACEMENT_TYPE.UPPER_LEFT );
1145             }
1146             else if ( type_str.equalsIgnoreCase( OVERVIEW_PLACEMENT_TYPE.UPPER_RIGHT.toTag() ) ) {
1147                 setOvPlacement( OVERVIEW_PLACEMENT_TYPE.UPPER_RIGHT );
1148             }
1149             else if ( type_str.equalsIgnoreCase( OVERVIEW_PLACEMENT_TYPE.LOWER_LEFT.toTag() ) ) {
1150                 setOvPlacement( OVERVIEW_PLACEMENT_TYPE.LOWER_LEFT );
1151             }
1152             else if ( type_str.equalsIgnoreCase( OVERVIEW_PLACEMENT_TYPE.LOWER_RIGHT.toTag() ) ) {
1153                 setOvPlacement( OVERVIEW_PLACEMENT_TYPE.LOWER_RIGHT );
1154             }
1155             else {
1156                 setOvPlacement( OVERVIEW_PLACEMENT_TYPE.UPPER_LEFT );
1157                 ForesterUtil.printWarningMessage( Constants.PRG_NAME, "unknown value [" + type_str
1158                         + "] for [overview_placement_type]" );
1159             }
1160         }
1161         else if ( key.equals( "node_label_direction" ) ) {
1162             final String type_str = ( ( String ) st.nextElement() ).trim();
1163             if ( type_str.equalsIgnoreCase( NODE_LABEL_DIRECTION.HORIZONTAL.toString() ) ) {
1164                 setNodeLabelDirection( NODE_LABEL_DIRECTION.HORIZONTAL );
1165             }
1166             else if ( type_str.equalsIgnoreCase( NODE_LABEL_DIRECTION.RADIAL.toString() ) ) {
1167                 setNodeLabelDirection( NODE_LABEL_DIRECTION.RADIAL );
1168             }
1169             else {
1170                 setNodeLabelDirection( NODE_LABEL_DIRECTION.HORIZONTAL );
1171                 ForesterUtil.printWarningMessage( Constants.PRG_NAME, "unknown value [" + type_str
1172                         + "] for [node_label_direction]" );
1173             }
1174         }
1175         else if ( key.equals( "branch_length_value_digits" ) ) {
1176             final short i = parseShort( ( ( String ) st.nextElement() ).trim() );
1177             if ( i >= 0 ) {
1178                 setNumberOfDigitsAfterCommaForBranchLengthValue( i );
1179             }
1180             else {
1181                 ForesterUtil.printWarningMessage( Constants.PRG_NAME, "illegal value [" + i
1182                         + "] for [branch_length_value_digits]" );
1183             }
1184         }
1185         else if ( key.equals( "confidence_value_digits" ) ) {
1186             final short i = parseShort( ( ( String ) st.nextElement() ).trim() );
1187             if ( i >= 0 ) {
1188                 setNumberOfDigitsAfterCommaForConfidenceValues( i );
1189             }
1190             else {
1191                 ForesterUtil.printWarningMessage( Constants.PRG_NAME, "illegal value [" + i
1192                         + "] for [confidence_value_digits]" );
1193             }
1194         }
1195         else if ( key.equals( "allow_editing" ) ) {
1196             setEditable( parseBoolean( ( String ) st.nextElement() ) );
1197         }
1198         else if ( key.equals( "display_sequence_relations" ) ) {
1199             setDisplaySequenceRelations( parseBoolean( ( String ) st.nextElement() ) );
1200         }
1201         else if ( key.equals( "replace_underscores_in_nh_parsing" ) ) {
1202             final boolean r = parseBoolean( ( String ) st.nextElement() );
1203             if ( r && isExtractPfamTaxonomyCodesInNhParsing() ) {
1204                 ForesterUtil
1205                         .printWarningMessage( Constants.PRG_NAME,
1206                                               "attempt to extract taxonomies and replace underscores at the same time" );
1207             }
1208             else {
1209                 setReplaceUnderscoresInNhParsing( r );
1210             }
1211         }
1212         else if ( key.equals( "extract_taxonomy_codes_in_nh_parsing" ) ) {
1213             final boolean e = parseBoolean( ( String ) st.nextElement() );
1214             if ( e && isReplaceUnderscoresInNhParsing() ) {
1215                 ForesterUtil
1216                         .printWarningMessage( Constants.PRG_NAME,
1217                                               "attempt to extract taxonomies and replace underscores at the same time" );
1218             }
1219             else {
1220                 setExtractPfamTaxonomyCodesInNhParsing( e );
1221             }
1222         }
1223         else if ( key.equals( "internal_labels_are_confidence_values" ) ) {
1224             setInternalNumberAreConfidenceForNhParsing( parseBoolean( ( String ) st.nextElement() ) );
1225         }
1226         else if ( key.equals( "gui_background_color" ) ) {
1227             _gui_background_color = Color.decode( ( String ) st.nextElement() );
1228         }
1229         else if ( key.equals( "gui_checkbox_text_color" ) ) {
1230             _gui_checkbox_text_color = Color.decode( ( String ) st.nextElement() );
1231         }
1232         else if ( key.equals( "gui_checkbox_and_button_active_color" ) ) {
1233             _gui_checkbox_and_button_active_color = Color.decode( ( String ) st.nextElement() );
1234         }
1235         else if ( key.equals( "gui_button_text_color" ) ) {
1236             _gui_button_text_color = Color.decode( ( String ) st.nextElement() );
1237         }
1238         else if ( key.equals( "gui_button_background_color" ) ) {
1239             _gui_button_background_color = Color.decode( ( String ) st.nextElement() );
1240         }
1241         else if ( key.equals( "gui_menu_background_color" ) ) {
1242             _gui_menu_background_color = Color.decode( ( String ) st.nextElement() );
1243         }
1244         else if ( key.equals( "gui_menu_text_color" ) ) {
1245             _gui_menu_text_color = Color.decode( ( String ) st.nextElement() );
1246         }
1247         else if ( key.equals( "gui_button_border_color" ) ) {
1248             _gui_button_border_color = Color.decode( ( String ) st.nextElement() );
1249         }
1250         else if ( key.equals( "domain_structure_font_color" ) ) {
1251             _domain_structure_font_color = Color.decode( ( String ) st.nextElement() );
1252         }
1253         else if ( key.equals( "domain_structure_base_color" ) ) {
1254             _domain_structure_base_color = Color.decode( ( String ) st.nextElement() );
1255         }
1256         else if ( key.equals( "show_default_node_shapes" ) ) {
1257             setShowDefaultNodeShapes( parseBoolean( ( ( String ) st.nextElement() ).trim() ) );
1258         }
1259         else if ( key.equals( "default_node_size" ) ) {
1260             final short i = parseShort( ( ( String ) st.nextElement() ).trim() );
1261             setDefaultNodeShapeSize( i );
1262         }
1263         else if ( key.equals( "default_node_fill" ) ) {
1264             final String fill_str = ( ( String ) st.nextElement() ).trim();
1265             if ( fill_str.equalsIgnoreCase( NodeVisualization.NodeFill.NONE.toString() ) ) {
1266                 setDefaultNodeFill( NodeFill.NONE );
1267             }
1268             else if ( fill_str.equalsIgnoreCase( NodeVisualization.NodeFill.GRADIENT.toString() ) ) {
1269                 setDefaultNodeFill( NodeFill.GRADIENT );
1270             }
1271             else if ( fill_str.equalsIgnoreCase( NodeVisualization.NodeFill.SOLID.toString() ) ) {
1272                 setDefaultNodeFill( NodeFill.SOLID );
1273             }
1274             else {
1275                 ForesterUtil.printWarningMessage( Constants.PRG_NAME, "unknown value [" + fill_str
1276                         + "] for [default_node_fill]" );
1277             }
1278         }
1279         else if ( key.equals( "default_node_shape" ) ) {
1280             final String shape_str = ( ( String ) st.nextElement() ).trim();
1281             if ( shape_str.equalsIgnoreCase( NodeVisualization.NodeShape.CIRCLE.toString() ) ) {
1282                 setDefaultNodeShape( NodeShape.CIRCLE );
1283             }
1284             else if ( shape_str.equalsIgnoreCase( NodeVisualization.NodeShape.RECTANGLE.toString() ) ) {
1285                 setDefaultNodeShape( NodeShape.RECTANGLE );
1286             }
1287             else {
1288                 ForesterUtil.printWarningMessage( Constants.PRG_NAME, "unknown value [" + shape_str
1289                         + "] for [default_node_shape]" );
1290             }
1291         }
1292         else if ( key.equals( "taxonomy_colorize_node_shapes" ) ) {
1293             setTaxonomyColorizeNodeShapes( parseBoolean( ( String ) st.nextElement() ) );
1294         }
1295         else if ( key.equals( "ext_descendents_data_to_return" ) ) {
1296             final String s = ( ( String ) st.nextElement() ).trim();
1297             if ( s.equalsIgnoreCase( "node_name" ) ) {
1298                 setExtDescNodeDataToReturn( NODE_DATA.NODE_NAME );
1299             }
1300             else if ( s.equalsIgnoreCase( "sequence_acc" ) ) {
1301                 setExtDescNodeDataToReturn( NODE_DATA.SEQUENCE_ACC );
1302             }
1303             else if ( s.equalsIgnoreCase( "sequence_mol_seq" ) ) {
1304                 setExtDescNodeDataToReturn( NODE_DATA.SEQUENCE_MOL_SEQ );
1305             }
1306             else if ( s.equalsIgnoreCase( "sequence_name" ) ) {
1307                 setExtDescNodeDataToReturn( NODE_DATA.SEQUENCE_NAME );
1308             }
1309             else if ( s.equalsIgnoreCase( "sequence_symbol" ) ) {
1310                 setExtDescNodeDataToReturn( NODE_DATA.SEQUENCE_SYMBOL );
1311             }
1312             else if ( s.equalsIgnoreCase( "taxonomy_scientific_name" ) ) {
1313                 setExtDescNodeDataToReturn( NODE_DATA.TAXONOMY_SCIENTIFIC_NAME );
1314             }
1315             else if ( s.equalsIgnoreCase( "taxonomy_code" ) ) {
1316                 setExtDescNodeDataToReturn( NODE_DATA.TAXONOMY_CODE );
1317             }
1318             else {
1319                 ForesterUtil.printWarningMessage( Constants.PRG_NAME, "unknown value [" + s
1320                         + "] for [ext_descendents_data_to_return]" );
1321             }
1322         }
1323         else if ( key.equals( "label_for_get_ext_descendents_data" ) ) {
1324             final String s = ( ( String ) st.nextElement() ).trim();
1325             if ( ForesterUtil.isEmpty( s ) || ( s.length() < 2 ) ) {
1326                 ForesterUtil.printWarningMessage( Constants.PRG_NAME, "illegal value [" + s
1327                         + "] for [label_for_get_ext_descendents_data]" );
1328             }
1329             else {
1330                 setLabelForGetExtDescendentsData( s.replaceAll( "_", " " ) );
1331             }
1332         }
1333         else if ( key.equals( "ext_descendents_data_to_return_on" ) ) {
1334             final String s = ( ( String ) st.nextElement() ).trim().toLowerCase();
1335             if ( s.equals( "console" ) ) {
1336                 setExtNodeDataReturnOn( EXT_NODE_DATA_RETURN_ON.CONSOLE );
1337             }
1338             else if ( s.equals( "window" ) ) {
1339                 setExtNodeDataReturnOn( EXT_NODE_DATA_RETURN_ON.WINODW );
1340             }
1341             else {
1342                 ForesterUtil.printWarningMessage( Constants.PRG_NAME, "unknown value [" + s
1343                         + "] for [ext_descendents_data_to_return_on]" );
1344             }
1345         }
1346         else if ( st.countTokens() >= 2 ) { // counts the tokens that are not
1347             // yet retrieved!
1348             int key_index = -1;
1349             if ( key.equals( "use_real_br_lengths" ) || key.equals( "phylogram" ) ) {
1350                 key_index = Configuration.display_as_phylogram;
1351                 if ( key.equals( "use_real_br_lengths" ) ) {
1352                     ForesterUtil
1353                             .printWarningMessage( Constants.PRG_NAME,
1354                                                   "configuration key [use_real_br_lengths] is deprecated, use [phylogram] instead" );
1355                 }
1356             }
1357             else if ( key.equals( "rollover" ) ) {
1358                 key_index = Configuration.node_data_popup;
1359             }
1360             else if ( key.equals( "color_according_to_species" ) ) {
1361                 key_index = Configuration.color_according_to_species;
1362             }
1363             else if ( key.equals( "show_node_names" ) ) {
1364                 key_index = Configuration.show_node_names;
1365             }
1366             else if ( key.equals( "show_taxonomy" ) || key.equals( "show_taxonomy_code" ) ) {
1367                 key_index = Configuration.show_tax_code;
1368                 if ( key.equals( "show_taxonomy" ) ) {
1369                     ForesterUtil
1370                             .printWarningMessage( Constants.PRG_NAME,
1371                                                   "configuration key [show_taxonomy] is deprecated, use [show_taxonomy_code] instead" );
1372                 }
1373             }
1374             else if ( key.equals( "write_br_length_values" ) ) {
1375                 ForesterUtil.printWarningMessage( Constants.PRG_NAME,
1376                                                   "configuration key [write_br_length_values] is deprecated" );
1377                 key_index = DEPRECATED;
1378             }
1379             else if ( key.equals( "write_bootstrap_values" ) || key.equals( "write_confidence_values" ) ) {
1380                 key_index = Configuration.write_confidence_values;
1381                 if ( key.equals( "write_bootstrap_values" ) ) {
1382                     ForesterUtil
1383                             .printWarningMessage( Constants.PRG_NAME,
1384                                                   "configuration key [write_bootstrap_values] is deprecated, use [write_confidence_values] instead" );
1385                 }
1386             }
1387             else if ( key.equals( "write_events" ) || key.equals( "write_dup_spec" ) ) {
1388                 key_index = Configuration.write_events;
1389                 if ( key.equals( "write_dup_spec" ) ) {
1390                     ForesterUtil
1391                             .printWarningMessage( Constants.PRG_NAME,
1392                                                   "configuration key [write_dup_spec] is deprecated, use [write_events] instead" );
1393                 }
1394             }
1395             else if ( key.equals( "color_branches" ) ) {
1396                 key_index = Configuration.color_branches;
1397             }
1398             else if ( key.equals( "width_branches" ) ) {
1399                 key_index = Configuration.width_branches;
1400             }
1401             else if ( key.equals( "color_orthologous" ) ) {
1402                 ForesterUtil.printWarningMessage( Constants.PRG_NAME,
1403                                                   "configuration key [color_orthologous] is deprecated" );
1404             }
1405             else if ( key.equals( "color_subtree_neighbors" ) ) {
1406                 ForesterUtil.printWarningMessage( Constants.PRG_NAME,
1407                                                   "configuration key [color_subtree_neighbors] is deprecated" );
1408             }
1409             else if ( key.equals( "color_super_orthologous" ) ) {
1410                 ForesterUtil.printWarningMessage( Constants.PRG_NAME,
1411                                                   "configuration key [color_super_orthologous] is deprecated" );
1412             }
1413             else if ( key.equals( "mark_nodes_with_box" ) ) {
1414                 ForesterUtil.printWarningMessage( Constants.PRG_NAME,
1415                                                   "configuration key [mark_nodes_with_box] is deprecated" );
1416                 key_index = DEPRECATED;
1417             }
1418             else if ( key.equals( "show_domain_architectures" ) ) {
1419                 key_index = Configuration.show_domain_architectures;
1420             }
1421             else if ( key.equals( "show_annotations" ) ) {
1422                 key_index = Configuration.show_annotation;
1423             }
1424             else if ( key.equals( "show_binary_characters" ) ) {
1425                 key_index = Configuration.show_binary_characters;
1426             }
1427             else if ( key.equals( "show_binary_character_counts" ) ) {
1428                 key_index = Configuration.show_binary_character_counts;
1429             }
1430             else if ( key.equals( "show_gene_names" ) ) {
1431                 key_index = Configuration.show_gene_names;
1432             }
1433             else if ( key.equals( "show_gene_symbols" ) ) {
1434                 key_index = Configuration.show_gene_symbols;
1435             }
1436             else if ( key.equals( "show_sequence_acc" ) ) {
1437                 key_index = Configuration.show_sequence_acc;
1438             }
1439             else if ( key.equals( "show_node_ids" ) ) {
1440                 ForesterUtil
1441                         .printWarningMessage( Constants.PRG_NAME, "configuration key [show_node_ids] is deprecated" );
1442                 key_index = DEPRECATED;
1443             }
1444             else if ( key.equals( "display_internal_data" ) ) {
1445                 key_index = Configuration.display_internal_data;
1446             }
1447             else if ( key.equals( "dynamically_hide_data" ) ) {
1448                 key_index = Configuration.dynamically_hide_data;
1449             }
1450             else if ( key.equals( "show_taxonomy_names" ) ) {
1451                 ForesterUtil.printWarningMessage( Constants.PRG_NAME,
1452                                                   "configuration key [show_taxonomy_names] is deprecated" );
1453                 key_index = DEPRECATED;
1454             }
1455             else if ( key.equals( "show_taxonomy_scientific_names" ) ) {
1456                 key_index = Configuration.show_taxonomy_scientific_names;
1457             }
1458             else if ( key.equals( "show_taxonomy_common_names" ) ) {
1459                 key_index = Configuration.show_taxonomy_common_names;
1460             }
1461             else if ( key.equals( "show_taxonomy_images" ) ) {
1462                 key_index = Configuration.show_taxonomy_images;
1463             }
1464             else if ( key.equals( "color_according_to_annotation" ) ) {
1465                 key_index = Configuration.color_according_to_annotation;
1466             }
1467             else if ( key.equals( "show_vector_data" ) ) {
1468                 key_index = Configuration.show_vector_data;
1469             }
1470             else if ( key.equals( "show_properties" ) ) {
1471                 key_index = Configuration.show_properties;
1472             }
1473             else if ( key.equals( "show_relation_confidence" ) ) {
1474                 key_index = Configuration.show_relation_confidence;
1475             }
1476             else if ( key.equals( "show_custom_node_shapes" ) ) {
1477                 key_index = Configuration.show_custom_node_shapes;
1478             }
1479             // If we've found the key, set the values
1480             if ( key_index >= 0 ) {
1481                 display_options[ key_index ][ 1 ] = ( String ) st.nextElement();
1482                 display_options[ key_index ][ 2 ] = ( String ) st.nextElement();
1483                 // otherwise, keep looking
1484             }
1485             else {
1486                 if ( key_index == DEPRECATED ) {
1487                     // Deprecated.
1488                 }
1489                 else if ( key.equals( "click_to" ) ) {
1490                     final String click_to_name = ( String ) st.nextElement();
1491                     key_index = getClickToIndex( click_to_name );
1492                     if ( key_index >= 0 ) {
1493                         clickto_options[ key_index ][ 1 ] = ( String ) st.nextElement();
1494                     }
1495                     else if ( key_index == DEPRECATED ) {
1496                         // Deprecated.
1497                     }
1498                     else {
1499                         ForesterUtil.printWarningMessage( Constants.PRG_NAME, "unknown click-to option: "
1500                                 + click_to_name );
1501                     }
1502                 }
1503                 else if ( key.equals( "species_color" ) ) {
1504                     getSpeciesColors().put( ( String ) st.nextElement(), Color.decode( ( String ) st.nextElement() ) );
1505                 }
1506                 else if ( key.equals( "domain_color" ) ) {
1507                     getDomainColors().put( ( String ) st.nextElement(), Color.decode( ( String ) st.nextElement() ) );
1508                 }
1509                 else if ( key.equals( "annotation_color" ) ) {
1510                     getAnnotationColors()
1511                             .put( ( String ) st.nextElement(), Color.decode( ( String ) st.nextElement() ) );
1512                 }
1513                 else if ( key.equals( "function_color" ) ) {
1514                     ForesterUtil.printWarningMessage( Constants.PRG_NAME,
1515                                                       "configuration key [function_color] is deprecated" );
1516                 }
1517                 else if ( key.equals( DISPLAY_COLOR_KEY ) ) {
1518                     putDisplayColors( ( String ) st.nextElement(), Color.decode( ( String ) st.nextElement() ) );
1519                 }
1520                 else if ( key.equals( WEB_LINK_KEY ) ) {
1521                     if ( st.countTokens() == 3 ) {
1522                         createWebLink( ( String ) st.nextElement(),
1523                                        ( String ) st.nextElement(),
1524                                        ( String ) st.nextElement() );
1525                     }
1526                     else {
1527                         ForesterUtil.printWarningMessage( Constants.PRG_NAME,
1528                                                           "illegal format in configuration file for key [" + key + "]" );
1529                     }
1530                 }
1531                 else {
1532                     ForesterUtil.printWarningMessage( Constants.PRG_NAME, "unknown configuration key [" + key
1533                             + "] in: " + config_filename );
1534                 }
1535             }
1536         }
1537         else {
1538             ForesterUtil.printWarningMessage( Constants.PRG_NAME, "unknown configuration key [" + key + "] in: "
1539                     + config_filename );
1540         }
1541     }
1542
1543     private void setLabelForGetExtDescendentsData( final String label_for_get_ext_descendents_data ) {
1544         _label_for_get_ext_descendents_data = label_for_get_ext_descendents_data;
1545     }
1546
1547     public String getLabelForGetExtDescendentsData() {
1548         return _label_for_get_ext_descendents_data;
1549     }
1550
1551     public void setMinConfidenceValue( final double min_confidence_value ) {
1552         _min_confidence_value = min_confidence_value;
1553     }
1554
1555     public void setNodeLabelDirection( final NODE_LABEL_DIRECTION node_label_direction ) {
1556         _node_label_direction = node_label_direction;
1557     }
1558
1559     public void setNumberOfDigitsAfterCommaForBranchLengthValue( final short number_of_digits_after_comma_for_branch_length_values ) {
1560         _number_of_digits_after_comma_for_branch_length_values = number_of_digits_after_comma_for_branch_length_values;
1561     }
1562
1563     public void setNumberOfDigitsAfterCommaForConfidenceValues( final short number_of_digits_after_comma_for_confidence_values ) {
1564         _number_of_digits_after_comma_for_confidence_values = number_of_digits_after_comma_for_confidence_values;
1565     }
1566
1567     private void setOvMaxHeight( final short ov_max_height ) {
1568         _ov_max_height = ov_max_height;
1569     }
1570
1571     private void setOvMaxWidth( final short ov_max_width ) {
1572         _ov_max_width = ov_max_width;
1573     }
1574
1575     private void setOvPlacement( final OVERVIEW_PLACEMENT_TYPE ov_placement ) {
1576         _ov_placement = ov_placement;
1577     }
1578
1579     public void setPhylogenyGraphicsType( final PHYLOGENY_GRAPHICS_TYPE phylogeny_graphics_type ) {
1580         _phylogeny_graphics_type = phylogeny_graphics_type;
1581     }
1582
1583     public void setPrintLineWidth( final float print_line_width ) {
1584         _print_line_width = print_line_width;
1585     }
1586
1587     public void setReplaceUnderscoresInNhParsing( final boolean nh_parsing_replace_underscores ) {
1588         _nh_parsing_replace_underscores = nh_parsing_replace_underscores;
1589     }
1590
1591     public void setShowBranchLengthValues( final boolean show_branch_length_values ) {
1592         _show_branch_length_values = show_branch_length_values;
1593     }
1594
1595     public void setShowDefaultNodeShapes( final boolean show_default_node_shapes ) {
1596         _show_default_node_shapes = show_default_node_shapes;
1597     }
1598
1599     public void setShowDomainLabels( final boolean show_domain_labels ) {
1600         _show_domain_labels = show_domain_labels;
1601     }
1602
1603     private void setShowOverview( final boolean show_overview ) {
1604         _show_overview = show_overview;
1605     }
1606
1607     public void setShowScale( final boolean show_scale ) {
1608         _show_scale = show_scale;
1609     }
1610
1611     public void setTaxonomyColorize( final boolean b ) {
1612         display_options[ color_according_to_species ][ 2 ] = b ? "yes" : "no";
1613     }
1614
1615     public void setTaxonomyColorizeNodeShapes( final boolean taxonomy_colorize_node_shapes ) {
1616         _taxonomy_colorize_node_shapes = taxonomy_colorize_node_shapes;
1617     }
1618
1619     public void setUseBranchesWidths( final boolean b ) {
1620         display_options[ width_branches ][ 2 ] = b ? "yes" : "no";
1621     }
1622
1623     private void setValidatePhyloXmlAgainstSchema( final boolean validate_against_phyloxml_xsd_schema ) {
1624         _validate_against_phyloxml_xsd_schema = validate_against_phyloxml_xsd_schema;
1625     }
1626
1627     void setWebLinks( final SortedMap<String, WebLink> weblinks ) {
1628         _weblinks = weblinks;
1629     }
1630
1631     static String getDefaultFontFamilyName() {
1632         return DEFAULT_FONT_FAMILY;
1633     }
1634
1635     static enum TRIPLET {
1636         TRUE, FALSE, UNKNOWN
1637     }
1638
1639     public enum UI {
1640         NATIVE, CROSSPLATFORM, NIMBUS, UNKNOWN
1641     }
1642
1643     public NODE_DATA getExtDescNodeDataToReturn() {
1644         return _ext_desc_data_to_return;
1645     }
1646
1647     public void setExtDescNodeDataToReturn( final NODE_DATA ext_desc_data_to_return ) {
1648         _ext_desc_data_to_return = ext_desc_data_to_return;
1649     }
1650
1651     public EXT_NODE_DATA_RETURN_ON getExtNodeDataReturnOn() {
1652         return _ext_node_data_return_on;
1653     }
1654
1655     private void setExtNodeDataReturnOn( final EXT_NODE_DATA_RETURN_ON ext_node_data_return_on ) {
1656         _ext_node_data_return_on = ext_node_data_return_on;
1657     }
1658 }