refactored
[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.util.ForesterUtil;
51
52 public final class Configuration {
53
54     public enum UI {
55         NATIVE, CROSSPLATFORM, NIMBUS, UNKNOWN
56     }
57     static final String                     VALIDATE_AGAINST_PHYLOXML_XSD_SCHEMA                   = "validate_against_phyloxml_xsd_schema";
58     private static final String             WEB_LINK_KEY                                           = "web_link";
59     private static final String             DISPLAY_COLOR_KEY                                      = "display_color";
60     private static final int                DEPRECATED                                             = -2;
61     private UI                              _ui                                                    = UI.UNKNOWN;
62     private boolean                         _use_tabbed_display                                    = false;
63     private boolean                         _hide_controls_and_menus                               = false;
64     private CLADOGRAM_TYPE                  _cladogram_type                                        = Constants.CLADOGRAM_TYPE_DEFAULT;
65     private SortedMap<String, WebLink>      _weblinks                                              = null;
66     private SortedMap<String, Color>        _display_colors                                        = null;
67     private boolean                         _antialias_screen                                      = true;
68     private PHYLOGENY_GRAPHICS_TYPE         _phylogeny_graphics_type                               = PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR;
69     private String                          _base_font_family_name                                 = "";
70     private int                             _base_font_size                                        = -1;
71     private int                             _graphics_export_x                                     = -1;
72     private int                             _graphics_export_y                                     = -1;
73     private short                           _ov_max_width                                          = 80;
74     private short                           _ov_max_height                                         = 80;
75     private OVERVIEW_PLACEMENT_TYPE         _ov_placement                                          = OVERVIEW_PLACEMENT_TYPE.UPPER_LEFT;
76     private double                          _min_confidence_value                                  = Options.MIN_CONFIDENCE_DEFAULT;
77     private float                           _print_line_width                                      = Constants.PDF_LINE_WIDTH_DEFAULT;
78     private boolean                         _show_scale                                            = false;
79     private boolean                         _show_branch_length_values                             = false;
80     private boolean                         _show_overview                                         = true;
81     private short                           _number_of_digits_after_comma_for_confidence_values    = Constants.NUMBER_OF_DIGITS_AFTER_COMMA_FOR_CONFIDENCE_VALUES_DEFAULT;
82     private short                           _number_of_digits_after_comma_for_branch_length_values = Constants.NUMBER_OF_DIGITS_AFTER_COMMA_FOR_BRANCH_LENGTH_VALUES_DEFAULT;
83     private boolean                         _editable                                              = true;
84     private boolean                         _nh_parsing_replace_underscores                        = false;
85     private boolean                         _nh_parsing_extract_pfam_taxonomy_codes                = false;
86     private boolean                         _internal_number_are_confidence_for_nh_parsing         = false;
87     private boolean                         _display_sequence_relations                            = false;
88     private boolean                         _validate_against_phyloxml_xsd_schema                  = Constants.VALIDATE_AGAINST_PHYLOXML_XSD_SCJEMA_DEFAULT;
89     private boolean                         _background_color_gradient                             = false;
90     private boolean                         _show_domain_labels                                    = true;
91     private boolean                         _abbreviate_scientific_names                           = false;
92     private boolean                         _color_labels_same_as_parent_branch                    = false;
93     private int                             _default_bootstrap_samples                             = -1;
94     final static int                        display_as_phylogram                                   = 0;
95     final static int                        show_node_names                                        = 1;
96     final static int                        show_tax_code                                          = 2;
97     final static int                        show_annotation                                        = 3;
98     final static int                        write_confidence_values                                = 4;
99     final static int                        write_events                                           = 5;
100     final static int                        color_according_to_species                             = 6;
101     final static int                        color_branches                                         = 7;
102     final static int                        width_branches                                         = 8;
103     final static int                        show_domain_architectures                              = 9;
104     final static int                        show_binary_characters                                 = 10;
105     final static int                        show_binary_character_counts                           = 11;
106     final static int                        show_gene_names                                        = 12;
107     final static int                        show_sequence_acc                                      = 13;
108     final static int                        display_internal_data                                  = 14;
109     final static int                        dynamically_hide_data                                  = 15;
110     final static int                        show_taxonomy_scientific_names                         = 16;
111     final static int                        show_taxonomy_common_names                             = 17;
112     final static int                        color_according_to_annotation                          = 18;
113     final static int                        show_property                                          = 19;
114     final static int                        show_gene_symbols                                      = 20;
115     final static int                        node_data_popup                                        = 21;
116     final static int                        show_relation_confidence                               = 22;
117     final static int                        show_vector_data                                       = 23;
118     final static int                        show_taxonomy_images                                   = 24;
119     // ------------------
120     // Click-to options
121     // ------------------
122     final static int                        display_node_data                                      = 0;
123     final static int                        collapse_uncollapse                                    = 1;
124     final static int                        reroot                                                 = 2;
125     final static int                        subtree                                                = 3;
126     final static int                        swap                                                   = 4;
127     final static int                        color_subtree                                          = 5;
128     final static int                        open_seq_web                                           = 6;
129     final static int                        open_tax_web                                           = 7;
130     final static int                        cut_subtree                                            = 8;
131     final static int                        copy_subtree                                           = 9;
132     final static int                        paste_subtree                                          = 10;
133     final static int                        delete_subtree_or_node                                 = 11;
134     final static int                        add_new_node                                           = 12;
135     final static int                        edit_node_data                                         = 13;
136     final static int                        blast                                                  = 14;
137     // ---------------------------
138     // Display options for trees
139     // ---------------------------
140     // ---------------------------------
141     // Pertaining to the config itself
142     // ---------------------------------
143     // Full path to config (may be URL)
144     String                                  config_filename;
145     String                                  default_config_filename                                = Constants.DEFAULT_CONFIGURATION_FILE_NAME;
146     final static String                     display_options[][]                                    = {
147             { "Phylogram", "display", "?" }, { "Node Name", "display", "yes" }, { "Taxonomy Code", "display", "yes" },
148             { "Annotation", "nodisplay", "no" }, { "Confidence Value", "display", "?" }, { "Event", "display", "?" },
149             { "Taxonomy Colorize", "display", "yes" }, { "Colorize Branches", "display", "no" },
150             { "Use Branch-Width", "nodisplay", "no" }, { "Domains", "nodisplay", "no" },
151             { "Binary Characters", "nodisplay", "no" }, { "Binary Char Counts", "nodisplay", "no" },
152             { "Prot/Gene Name", "display", "no" }, { "Prot/Gene Acc", "display", "no" },
153             { "Show Internal Data", "display", "yes" }, { "Dyna Hide", "display", "yes" },
154             { "Taxonomy Scientific", "display", "yes" }, { "Taxonomy Common", "display", "no" },
155             { "Annotation Colorize", "nodisplay", "no" }, { "Property", "nodisplay", "no" },
156             { "Prot/Gene Symbol", "display", "no" }, { "Rollover", "display", "yes" },
157             { "Relation Confidence", "display", "no" }, { "Vector Data", "display", "no" },
158             { "Taxonomy Images", "display", "no" }                                                };
159     final static String                     clickto_options[][]                                    = {
160             { "Display Node Data", "display" }, { "Collapse/Uncollapse", "display" }, { "Root/Reroot", "display" },
161             { "Sub/Super Tree", "display" }, { "Swap Descendants", "display" }, { "Colorize Subtree", "display" },
162             { "Open Sequence Web", "nodisplay" }, { "Open Taxonomy Web", "nodisplay" }, { "Cut Subtree", "display" },
163             { "Copy Subtree", "display" }, { "Paste Subtree", "display" }, { "Delete Subtree/Node", "display" },
164             { "Add New Node", "display" }, { "Edit Node Data", "display" }, { "Blast", "display" } };
165     // This option is selected in the dropdown
166     int                                     default_clickto                                        = Configuration.display_node_data;
167     // --------------
168     // Color set
169     // --------------
170     TreeColorSet                            tree_color_set;
171     // -------
172     // Fonts
173     // -------
174     TreeFontSet                             tree_font_set;
175     // ----------------
176     // Species colors
177     // ----------------
178     private static Hashtable<String, Color> _species_colors;
179     // ----------------
180     // Domain colors
181     // ----------------
182     private static Hashtable<String, Color> _domain_colors;
183     // ----------------
184     // Function colors
185     // ----------------
186     private static Hashtable<String, Color> _annotation_colors;
187     boolean                                 verbose                                                = Constants.VERBOSE_DEFAULT;
188     private NODE_LABEL_DIRECTION            _node_label_direction                                  = NODE_LABEL_DIRECTION.HORIZONTAL;
189     private Color                           _gui_background_color                                  = Constants.GUI_BACKGROUND_DEFAULT;
190     private Color                           _gui_checkbox_text_color                               = Constants.CHECKBOX_TEXT_COLOR_DEFAULT;
191     private Color                           _gui_checkbox_and_button_active_color                  = Constants.CHECKBOX_AND_BUTTON_ACTIVE_COLOR_DEFAULT;
192     private Color                           _gui_button_text_color                                 = Constants.BUTTON_TEXT_COLOR_DEFAULT;
193     private Color                           _gui_button_background_color                           = Constants.BUTTON_BACKGROUND_COLOR_DEFAULT;
194     private Color                           _gui_menu_background_color                             = Constants.MENU_BACKGROUND_COLOR_DEFAULT;
195     private Color                           _gui_menu_text_color                                   = Constants.MENU_TEXT_COLOR_DEFAULT;
196     private Color                           _gui_button_border_color                               = Constants.BUTTON_BORDER_COLOR_DEFAULT;
197     private Color                           _domain_structure_font_color                           = Constants.DOMAIN_STRUCTURE_FONT_COLOR_DEFAULT;
198     private Color                           _domain_structure_base_color                           = Constants.DOMAIN_STRUCTURE_BASE_COLOR_DEFAULT;
199     private static String                   DEFAULT_FONT_FAMILY                                    = "";
200     static {
201         for( final String font_name : Constants.DEFAULT_FONT_CHOICES ) {
202             if ( Arrays.binarySearch( Util.getAvailableFontFamiliesSorted(), font_name ) >= 0 ) {
203                 DEFAULT_FONT_FAMILY = font_name;
204                 break;
205             }
206         }
207         if ( ForesterUtil.isEmpty( DEFAULT_FONT_FAMILY ) ) {
208             DEFAULT_FONT_FAMILY = Constants.DEFAULT_FONT_CHOICES[ Constants.DEFAULT_FONT_CHOICES.length - 1 ];
209         }
210     }
211
212     Configuration( final String cf, final boolean is_url, final boolean is_applet ) {
213         if ( ForesterUtil.isEmpty( cf ) ) {
214             config_filename = default_config_filename;
215         }
216         else {
217             config_filename = cf;
218         }
219         setWebLinks( new TreeMap<String, WebLink>() );
220         setDisplayColors( new TreeMap<String, Color>() );
221         config_filename = config_filename.trim();
222         URL u = null;
223         if ( is_url ) {
224             // If URL, open accordingly
225             try {
226                 u = new URL( config_filename );
227                 try {
228                     final InputStreamReader isr = new InputStreamReader( u.openStream() );
229                     final BufferedReader bf = new BufferedReader( isr );
230                     readConfig( bf );
231                     bf.close();
232                     ForesterUtil.programMessage( Constants.PRG_NAME, "successfully read from configuration url ["
233                             + config_filename + "]" );
234                 }
235                 catch ( final Exception e ) {
236                     ForesterUtil.printWarningMessage( Constants.PRG_NAME, "failed to read configuration from ["
237                             + config_filename + "]: " + e.getLocalizedMessage() );
238                 }
239             }
240             catch ( final Exception e ) {
241                 ForesterUtil.printWarningMessage( Constants.PRG_NAME, "cannot find or open configuration url ["
242                         + config_filename + "]" );
243             }
244         }
245         else {
246             // Otherwise, open as a file
247             File f = new File( config_filename );
248             if ( !f.exists() ) {
249                 f = new File( config_filename + ".txt" );
250             }
251             if ( f.exists() && f.canRead() ) {
252                 try {
253                     final BufferedReader bf = new BufferedReader( new FileReader( f ) );
254                     readConfig( bf );
255                     bf.close();
256                 }
257                 catch ( final Exception e ) {
258                     ForesterUtil.printWarningMessage( Constants.PRG_NAME, "failed to read configuration from ["
259                             + config_filename + "]: " + e );
260                 }
261             }
262             else {
263                 ForesterUtil.printWarningMessage( Constants.PRG_NAME, "cannot find or open configuration file ["
264                         + config_filename + "]" );
265             }
266         }
267     }
268
269     private void createWebLink( final String url_str, final String desc, final String source_identifier ) {
270         WebLink weblink = null;
271         boolean ex = false;
272         try {
273             weblink = new WebLink( new URL( url_str.trim() ), desc.trim(), source_identifier.trim() );
274         }
275         catch ( final MalformedURLException e ) {
276             ForesterUtil.printWarningMessage( Constants.PRG_NAME, "could not create URL from [" + url_str + "]" );
277             ex = true;
278         }
279         if ( !ex && ( weblink != null ) ) {
280             getWebLinks().put( weblink.getSourceIdentifier().toLowerCase(), weblink );
281         }
282     }
283
284     Color getGuiBackgroundColor() {
285         return _gui_background_color;
286     }
287
288     Color getGuiCheckboxTextColor() {
289         return _gui_checkbox_text_color;
290     }
291
292     Color getGuiCheckboxAndButtonActiveColor() {
293         return _gui_checkbox_and_button_active_color;
294     }
295
296     Color getGuiButtonTextColor() {
297         return _gui_button_text_color;
298     }
299
300     Color getGuiButtonBackgroundColor() {
301         return _gui_button_background_color;
302     }
303
304     Color getGuiMenuBackgroundColor() {
305         return _gui_menu_background_color;
306     }
307
308     Color getGuiMenuTextColor() {
309         return _gui_menu_text_color;
310     }
311
312     Color getGuiButtonBorderColor() {
313         return _gui_button_border_color;
314     }
315
316     boolean displaySequenceRelations() {
317         return _display_sequence_relations;
318     }
319
320     boolean doCheckOption( final int which ) {
321         return ( display_options[ which ][ 2 ].equalsIgnoreCase( "yes" ) )
322                 || ( display_options[ which ][ 2 ].equalsIgnoreCase( "true" ) );
323     }
324
325     boolean doDisplayClickToOption( final int which ) {
326         return clickto_options[ which ][ 1 ].equalsIgnoreCase( "display" );
327     }
328
329     boolean doDisplayOption( final int which ) {
330         return display_options[ which ][ 1 ].equalsIgnoreCase( "display" );
331     }
332
333     /**
334      * Will attempt to use the phylogeny to determine whether to check
335      * this or not (e.g. phylogram)
336      * 
337      */
338     boolean doGuessCheckOption( final int which ) {
339         return display_options[ which ][ 2 ].equals( "?" );
340     }
341
342     Map<String, Color> getAnnotationColors() {
343         if ( _annotation_colors == null ) {
344             _annotation_colors = new Hashtable<String, Color>();
345         }
346         return _annotation_colors;
347     }
348
349     public String getBaseFontFamilyName() {
350         return _base_font_family_name;
351     }
352
353     int getBaseFontSize() {
354         return _base_font_size;
355     }
356
357     CLADOGRAM_TYPE getCladogramType() {
358         return _cladogram_type;
359     }
360
361     private int getClickToIndex( final String name ) {
362         int index = -1;
363         if ( name.equals( "edit_info" ) ) {
364             index = Configuration.display_node_data;
365             ForesterUtil
366                     .printWarningMessage( Constants.PRG_NAME,
367                                           "configuration key [edit_info] is deprecated, use [display node data] instead" );
368         }
369         else if ( name.equals( "display_node_data" ) ) {
370             index = Configuration.display_node_data;
371         }
372         else if ( name.equals( "collapse_uncollapse" ) ) {
373             index = Configuration.collapse_uncollapse;
374         }
375         else if ( name.equals( "reroot" ) ) {
376             index = Configuration.reroot;
377         }
378         else if ( name.equals( "subtree" ) ) {
379             index = Configuration.subtree;
380         }
381         else if ( name.equals( "swap" ) ) {
382             index = Configuration.swap;
383         }
384         else if ( name.equals( "display_sequences" ) ) {
385             ForesterUtil
386                     .printWarningMessage( Constants.PRG_NAME, "configuration key [display_sequences] is deprecated" );
387             return DEPRECATED;
388         }
389         else if ( name.equals( "open_seq_web" ) ) {
390             index = Configuration.open_seq_web;
391         }
392         else if ( name.equals( "open_tax_web" ) ) {
393             index = Configuration.open_tax_web;
394         }
395         else if ( name.equals( "cut_subtree" ) ) {
396             index = Configuration.cut_subtree;
397         }
398         else if ( name.equals( "copy_subtree" ) ) {
399             index = Configuration.copy_subtree;
400         }
401         else if ( name.equals( "paste_subtree" ) ) {
402             index = Configuration.paste_subtree;
403         }
404         else if ( name.equals( "delete" ) ) {
405             index = Configuration.delete_subtree_or_node;
406         }
407         else if ( name.equals( "add_new_node" ) ) {
408             index = Configuration.add_new_node;
409         }
410         else if ( name.equals( "edit_node_data" ) ) {
411             index = Configuration.edit_node_data;
412         }
413         else if ( name.equals( "display_node_popup" ) ) {
414             ForesterUtil.printWarningMessage( Constants.PRG_NAME,
415                                               "configuration key [display_node_popup] is deprecated" );
416             return DEPRECATED;
417         }
418         else if ( name.equals( "custom_option" ) ) {
419             ForesterUtil.printWarningMessage( Constants.PRG_NAME, "configuration key [custom_option] is deprecated" );
420             return DEPRECATED;
421         }
422         else if ( name.equals( "color_subtree" ) ) {
423             index = Configuration.color_subtree;
424         }
425         else if ( name.equals( "go_to_swiss_prot" ) ) {
426             ForesterUtil.printWarningMessage( Constants.PRG_NAME, "configuration key [go_to_swiss_prot] is deprecated" );
427             return DEPRECATED;
428         }
429         return index;
430     }
431
432     int getClickToOptionsCount() {
433         return clickto_options.length;
434     }
435
436     String getClickToTitle( final int which ) {
437         return clickto_options[ which ][ 0 ];
438     }
439
440     int getDefaultDisplayClicktoOption() {
441         return default_clickto;
442     }
443
444     SortedMap<String, Color> getDisplayColors() {
445         return _display_colors;
446     }
447
448     String getDisplayTitle( final int which ) {
449         return display_options[ which ][ 0 ];
450     }
451
452     Map<String, Color> getDomainColors() {
453         if ( _domain_colors == null ) {
454             _domain_colors = new Hashtable<String, Color>();
455         }
456         return _domain_colors;
457     }
458
459     int getGraphicsExportX() {
460         return _graphics_export_x;
461     }
462
463     int getGraphicsExportY() {
464         return _graphics_export_y;
465     }
466
467     public int getDefaultBootstrapSamples() {
468         return _default_bootstrap_samples;
469     }
470
471     double getMinConfidenceValue() {
472         return _min_confidence_value;
473     }
474
475     NODE_LABEL_DIRECTION getNodeLabelDirection() {
476         return _node_label_direction;
477     }
478
479     short getNumberOfDigitsAfterCommaForBranchLengthValues() {
480         return _number_of_digits_after_comma_for_branch_length_values;
481     }
482
483     short getNumberOfDigitsAfterCommaForConfidenceValues() {
484         return _number_of_digits_after_comma_for_confidence_values;
485     }
486
487     short getOvMaxHeight() {
488         return _ov_max_height;
489     }
490
491     short getOvMaxWidth() {
492         return _ov_max_width;
493     }
494
495     OVERVIEW_PLACEMENT_TYPE getOvPlacement() {
496         return _ov_placement;
497     }
498
499     PHYLOGENY_GRAPHICS_TYPE getPhylogenyGraphicsType() {
500         return _phylogeny_graphics_type;
501     }
502
503     float getPrintLineWidth() {
504         return _print_line_width;
505     }
506
507     Hashtable<String, Color> getSpeciesColors() {
508         if ( _species_colors == null ) {
509             _species_colors = new Hashtable<String, Color>();
510         }
511         return _species_colors;
512     }
513
514     TreeColorSet getTreeColorSet() {
515         return null;
516     }
517
518     TreeFontSet getTreeFontSet() {
519         return null;
520     }
521
522     WebLink getWebLink( final String source ) {
523         return getWebLinks().get( source );
524     }
525
526     Map<String, WebLink> getWebLinks() {
527         return _weblinks;
528     }
529
530     boolean isAntialiasScreen() {
531         return _antialias_screen;
532     }
533
534     public boolean isBackgroundColorGradient() {
535         return _background_color_gradient;
536     }
537
538     /**
539      * Convenience method.
540      * 
541      * @return true if value in configuration file was 'yes'
542      */
543     boolean isDrawAsPhylogram() {
544         return doCheckOption( display_as_phylogram );
545     }
546
547     boolean isEditable() {
548         return _editable;
549     }
550
551     boolean isExtractPfamTaxonomyCodesInNhParsing() {
552         return _nh_parsing_extract_pfam_taxonomy_codes;
553     }
554
555     boolean isHasWebLink( final String source ) {
556         return getWebLinks().containsKey( source );
557     }
558
559     /**
560      * Only used by ArchaeoptryxE.
561      *
562      */
563     boolean isHideControlPanelAndMenubar() {
564         return _hide_controls_and_menus;
565     }
566
567     boolean isInternalNumberAreConfidenceForNhParsing() {
568         return _internal_number_are_confidence_for_nh_parsing;
569     }
570
571     boolean isReplaceUnderscoresInNhParsing() {
572         return _nh_parsing_replace_underscores;
573     }
574
575     boolean isShowBranchLengthValues() {
576         return _show_branch_length_values;
577     }
578
579     boolean isShowOverview() {
580         return _show_overview;
581     }
582
583     boolean isShowScale() {
584         return _show_scale;
585     }
586
587     final boolean isUseNativeUI() {
588         if ( ( _ui == UI.UNKNOWN ) && Util.isMac() && Util.isJava15() ) {
589             _ui = UI.NATIVE;
590         }
591         return _ui == UI.NATIVE;
592     }
593
594     /**
595      * Only used by ArchaeoptryxE.
596      *
597      */
598     boolean isUseTabbedDisplay() {
599         return _use_tabbed_display;
600     }
601
602     boolean isValidatePhyloXmlAgainstSchema() {
603         return _validate_against_phyloxml_xsd_schema;
604     }
605
606     private boolean parseBoolean( final String str ) {
607         final String my_str = str.trim().toLowerCase();
608         if ( my_str.equals( "yes" ) || my_str.equals( "true" ) ) {
609             return true;
610         }
611         else if ( my_str.equals( "no" ) || my_str.equals( "false" ) ) {
612             return false;
613         }
614         else {
615             ForesterUtil.printWarningMessage( Constants.PRG_NAME, "could not parse boolean value from [" + str + "]" );
616             return false;
617         }
618     }
619
620     private double parseDouble( final String str ) {
621         double d = 0.0;
622         try {
623             d = Double.parseDouble( str );
624         }
625         catch ( final Exception e ) {
626             ForesterUtil.printWarningMessage( Constants.PRG_NAME, "could not parse double from [" + str + "]" );
627             d = 0.0;
628         }
629         return d;
630     }
631
632     private float parseFloat( final String str ) {
633         float f = 0.0f;
634         try {
635             f = Float.parseFloat( str );
636         }
637         catch ( final Exception e ) {
638             ForesterUtil.printWarningMessage( Constants.PRG_NAME, "could not parse float from [" + str + "]" );
639             f = 0.0f;
640         }
641         return f;
642     }
643
644     private int parseInt( final String str ) {
645         int i = -1;
646         try {
647             i = Integer.parseInt( str );
648         }
649         catch ( final Exception e ) {
650             ForesterUtil.printWarningMessage( Constants.PRG_NAME, "could not parse integer from [" + str + "]" );
651             i = -1;
652         }
653         return i;
654     }
655
656     private short parseShort( final String str ) {
657         short i = -1;
658         try {
659             i = Short.parseShort( str );
660         }
661         catch ( final Exception e ) {
662             ForesterUtil.printWarningMessage( Constants.PRG_NAME, "could not parse short from [" + str + "]" );
663             i = -1;
664         }
665         return i;
666     }
667
668     private void processFontFamily( final StringTokenizer st ) {
669         setBaseFontFamilyName( "" );
670         final String font_str = ( ( String ) st.nextElement() ).trim();
671         final String[] fonts = font_str.split( ",+" );
672         for( String font : fonts ) {
673             font = font.replace( '_', ' ' ).trim();
674             if ( Arrays.binarySearch( Util.getAvailableFontFamiliesSorted(), font ) >= 0 ) {
675                 setBaseFontFamilyName( font );
676                 break;
677             }
678         }
679     }
680
681     /**
682      * read each line of config file, process non-comment lines
683      * @throws IOException 
684      */
685     private void readConfig( final BufferedReader conf_in ) throws IOException {
686         String line;
687         do {
688             line = conf_in.readLine();
689             if ( line != null ) {
690                 line = line.trim();
691                 // skip comments and blank lines
692                 if ( !line.startsWith( "#" ) && ( !ForesterUtil.isEmpty( line ) ) ) {
693                     // convert runs of spaces to tabs
694                     line = line.replaceAll( "\\s+", "\t" );
695                     final StringTokenizer st = new StringTokenizer( line, "\t" );
696                     setKeyValue( st );
697                 }
698             }
699         } while ( line != null );
700     }
701
702     private void setAntialiasScreen( final boolean antialias_screen ) {
703         _antialias_screen = antialias_screen;
704     }
705
706     public void setBackgroundColorGradient( final boolean background_color_gradient ) {
707         _background_color_gradient = background_color_gradient;
708     }
709
710     private void setBaseFontFamilyName( final String base_font_family_name ) {
711         _base_font_family_name = base_font_family_name;
712     }
713
714     private void setBaseFontSize( final int base_font_size ) {
715         _base_font_size = base_font_size;
716     }
717
718     private void setShowDomainLabels( final boolean show_domain_labels ) {
719         _show_domain_labels = show_domain_labels;
720     }
721
722     private void setAbbreviateScientificTaxonNames( final boolean abbreviate_scientific_names ) {
723         _abbreviate_scientific_names = abbreviate_scientific_names;
724     }
725
726     private void setColorLabelsSameAsParentBranch( final boolean color_labels_same_as_parent_branch ) {
727         _color_labels_same_as_parent_branch = color_labels_same_as_parent_branch;
728     }
729
730     private void setCladogramType( final CLADOGRAM_TYPE cladogram_type ) {
731         _cladogram_type = cladogram_type;
732     }
733
734     void setDisplayColors( final SortedMap<String, Color> display_colors ) {
735         _display_colors = display_colors;
736     }
737
738     private void setDisplaySequenceRelations( final boolean display_sequence_relations ) {
739         _display_sequence_relations = display_sequence_relations;
740     }
741
742     private void setEditable( final boolean editable ) {
743         _editable = editable;
744     }
745
746     private void setExtractPfamTaxonomyCodesInNhParsing( final boolean nh_parsing_extract_pfam_taxonomy_codes ) {
747         _nh_parsing_extract_pfam_taxonomy_codes = nh_parsing_extract_pfam_taxonomy_codes;
748     }
749
750     private void setGraphicsExportX( final int graphics_export_x ) {
751         _graphics_export_x = graphics_export_x;
752     }
753
754     private void setGraphicsExportY( final int graphics_export_y ) {
755         _graphics_export_y = graphics_export_y;
756     }
757
758     private void setDefaultBootstrapSamples( final int default_bootstrap_samples ) {
759         _default_bootstrap_samples = default_bootstrap_samples;
760     }
761
762     private void setInternalNumberAreConfidenceForNhParsing( final boolean internal_number_are_confidence_for_nh_parsing ) {
763         _internal_number_are_confidence_for_nh_parsing = internal_number_are_confidence_for_nh_parsing;
764     }
765
766     /**
767      * Set a key-value(s) tuple
768      */
769     private void setKeyValue( final StringTokenizer st ) {
770         String key = ( String ) st.nextElement();
771         key = key.replace( ':', ' ' );
772         key = key.trim();
773         key = key.toLowerCase();
774         // Handle single value settings first:
775         if ( key.equals( "default_click_to" ) ) {
776             final String clickto_name = ( String ) st.nextElement();
777             default_clickto = getClickToIndex( clickto_name );
778             if ( default_clickto == -1 ) {
779                 ForesterUtil.printWarningMessage( Constants.PRG_NAME, "invalid value [" + clickto_name
780                         + "] for [default_click_to]" );
781                 default_clickto = 0;
782             }
783             else if ( default_clickto == DEPRECATED ) {
784                 // Deprecated.
785             }
786         }
787         else if ( key.equals( "native_ui" ) ) {
788             final String my_str = ( ( String ) st.nextElement() ).trim().toLowerCase();
789             if ( my_str.equals( "yes" ) || my_str.equals( "true" ) ) {
790                 _ui = UI.NATIVE;
791             }
792             else if ( my_str.equals( "no" ) || my_str.equals( "false" ) ) {
793                 _ui = UI.CROSSPLATFORM;
794             }
795             else if ( my_str.equals( "?" ) ) {
796                 _ui = UI.UNKNOWN;
797             }
798             else {
799                 ForesterUtil.printWarningMessage( Constants.PRG_NAME, "could not parse yes/no/? value from [" + my_str
800                         + "]" );
801                 _ui = UI.UNKNOWN;
802             }
803         }
804         else if ( key.equals( VALIDATE_AGAINST_PHYLOXML_XSD_SCHEMA ) ) {
805             setValidatePhyloXmlAgainstSchema( parseBoolean( ( String ) st.nextElement() ) );
806         }
807         else if ( key.equals( "antialias_screen" ) ) {
808             setAntialiasScreen( parseBoolean( ( String ) st.nextElement() ) );
809         }
810         else if ( key.equals( "phylogeny_graphics_type" ) ) {
811             final String type_str = ( ( String ) st.nextElement() ).trim();
812             if ( type_str.equalsIgnoreCase( PHYLOGENY_GRAPHICS_TYPE.CONVEX.toString() ) ) {
813                 setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CONVEX );
814             }
815             else if ( type_str.equalsIgnoreCase( PHYLOGENY_GRAPHICS_TYPE.CURVED.toString() ) ) {
816                 setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CURVED );
817             }
818             else if ( type_str.equalsIgnoreCase( PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE.toString() ) ) {
819                 setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE );
820             }
821             else if ( type_str.equalsIgnoreCase( PHYLOGENY_GRAPHICS_TYPE.ROUNDED.toString() ) ) {
822                 setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.ROUNDED );
823             }
824             else if ( type_str.equalsIgnoreCase( PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR.toString() ) ) {
825                 setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR );
826             }
827             else if ( type_str.equalsIgnoreCase( PHYLOGENY_GRAPHICS_TYPE.TRIANGULAR.toString() ) ) {
828                 setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.TRIANGULAR );
829             }
830             else if ( type_str.equalsIgnoreCase( PHYLOGENY_GRAPHICS_TYPE.UNROOTED.toString() ) ) {
831                 setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.UNROOTED );
832             }
833             else if ( type_str.equalsIgnoreCase( PHYLOGENY_GRAPHICS_TYPE.CIRCULAR.toString() ) ) {
834                 setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CIRCULAR );
835             }
836             else {
837                 setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR );
838                 ForesterUtil.printWarningMessage( Constants.PRG_NAME, "unknown value [" + type_str
839                         + "] for [phylogeny_graphics_type]" );
840             }
841         }
842         else if ( key.equals( "min_confidence_value" ) ) {
843             final String mcv_str = ( ( String ) st.nextElement() ).trim();
844             final double d = parseDouble( mcv_str );
845             setMinConfidenceValue( d );
846         }
847         else if ( key.equals( "font_family" ) ) {
848             processFontFamily( st );
849         }
850         else if ( key.equals( "font_size" ) ) {
851             final String size_str = ( ( String ) st.nextElement() ).trim();
852             final int i = parseInt( size_str );
853             setBaseFontSize( i );
854         }
855         else if ( key.equals( "graphics_export_x" ) ) {
856             final String str = ( ( String ) st.nextElement() ).trim();
857             final int i = parseInt( str );
858             setGraphicsExportX( i );
859         }
860         else if ( key.equals( "graphics_export_y" ) ) {
861             final String str = ( ( String ) st.nextElement() ).trim();
862             final int i = parseInt( str );
863             setGraphicsExportY( i );
864         }
865         else if ( key.equals( "pdf_export_line_width" ) ) {
866             final String str = ( ( String ) st.nextElement() ).trim();
867             final float f = parseFloat( str );
868             if ( f > 0 ) {
869                 setPrintLineWidth( f );
870             }
871             else {
872                 ForesterUtil.printWarningMessage( Constants.PRG_NAME,
873                                                   "value for [pdf_export_line_width] cannot be zero or negative" );
874             }
875         }
876         else if ( key.equals( "default_number_of_bootstrap_resamples" ) ) {
877             final String str = ( ( String ) st.nextElement() ).trim();
878             final int i = parseInt( str );
879             if ( i >= 0 ) {
880                 setDefaultBootstrapSamples( i );
881             }
882             else {
883                 ForesterUtil
884                         .printWarningMessage( Constants.PRG_NAME,
885                                               "value for [default_number_of_bootstrap_resamples] cannot be negative" );
886             }
887         }
888         else if ( key.equals( "show_scale" ) ) {
889             setShowScale( parseBoolean( ( String ) st.nextElement() ) );
890         }
891         else if ( key.equals( "show_overview" ) ) {
892             setShowOverview( parseBoolean( ( String ) st.nextElement() ) );
893         }
894         else if ( key.equals( "show_branch_length_values" ) ) {
895             setShowBranchLengthValues( parseBoolean( ( String ) st.nextElement() ) );
896         }
897         else if ( key.equals( "background_gradient" ) ) {
898             setBackgroundColorGradient( parseBoolean( ( String ) st.nextElement() ) );
899         }
900         else if ( key.equals( "color_labels_same_as_branch_length_values" ) ) {
901             setColorLabelsSameAsParentBranch( parseBoolean( ( String ) st.nextElement() ) );
902         }
903         else if ( key.equals( "show_domain_labels" ) ) {
904             setShowDomainLabels( parseBoolean( ( String ) st.nextElement() ) );
905         }
906         else if ( key.equals( "abbreviate_scientific_names" ) ) {
907             setAbbreviateScientificTaxonNames( parseBoolean( ( String ) st.nextElement() ) );
908         }
909         else if ( key.equals( "cladogram_type" ) ) {
910             final String type_str = ( ( String ) st.nextElement() ).trim();
911             if ( type_str.equalsIgnoreCase( Options.CLADOGRAM_TYPE.NON_LINED_UP.toString() ) ) {
912                 setCladogramType( Options.CLADOGRAM_TYPE.NON_LINED_UP );
913             }
914             else if ( type_str.equalsIgnoreCase( Options.CLADOGRAM_TYPE.EXT_NODE_SUM_DEP.toString() ) ) {
915                 setCladogramType( Options.CLADOGRAM_TYPE.EXT_NODE_SUM_DEP );
916             }
917             else if ( type_str.equalsIgnoreCase( Options.CLADOGRAM_TYPE.TOTAL_NODE_SUM_DEP.toString() ) ) {
918                 setCladogramType( Options.CLADOGRAM_TYPE.TOTAL_NODE_SUM_DEP );
919             }
920             else {
921                 ForesterUtil.printWarningMessage( Constants.PRG_NAME, "unknown value [" + type_str
922                         + "] for [cladogram_type]" );
923             }
924         }
925         else if ( key.equals( "non_lined_up_cladogram" ) ) {
926             ForesterUtil
927                     .printWarningMessage( Constants.PRG_NAME,
928                                           "configuration key [non_lined_up_cladogram] is deprecated, use [cladogram_type] instead" );
929         }
930         else if ( key.equals( "hide_controls_and_menus" ) ) {
931             _hide_controls_and_menus = parseBoolean( ( String ) st.nextElement() );
932         }
933         else if ( key.equals( "use_tabbed_display" ) ) {
934             _use_tabbed_display = parseBoolean( ( String ) st.nextElement() );
935         }
936         else if ( key.equals( "overview_width" ) ) {
937             final short i = parseShort( ( ( String ) st.nextElement() ).trim() );
938             setOvMaxWidth( i );
939         }
940         else if ( key.equals( "overview_height" ) ) {
941             final short i = parseShort( ( ( String ) st.nextElement() ).trim() );
942             setOvMaxHeight( i );
943         }
944         else if ( key.equals( "overview_placement_type" ) ) {
945             final String type_str = ( ( String ) st.nextElement() ).trim();
946             if ( type_str.equalsIgnoreCase( OVERVIEW_PLACEMENT_TYPE.UPPER_LEFT.toTag() ) ) {
947                 setOvPlacement( OVERVIEW_PLACEMENT_TYPE.UPPER_LEFT );
948             }
949             else if ( type_str.equalsIgnoreCase( OVERVIEW_PLACEMENT_TYPE.UPPER_RIGHT.toTag() ) ) {
950                 setOvPlacement( OVERVIEW_PLACEMENT_TYPE.UPPER_RIGHT );
951             }
952             else if ( type_str.equalsIgnoreCase( OVERVIEW_PLACEMENT_TYPE.LOWER_LEFT.toTag() ) ) {
953                 setOvPlacement( OVERVIEW_PLACEMENT_TYPE.LOWER_LEFT );
954             }
955             else if ( type_str.equalsIgnoreCase( OVERVIEW_PLACEMENT_TYPE.LOWER_RIGHT.toTag() ) ) {
956                 setOvPlacement( OVERVIEW_PLACEMENT_TYPE.LOWER_RIGHT );
957             }
958             else {
959                 setOvPlacement( OVERVIEW_PLACEMENT_TYPE.UPPER_LEFT );
960                 ForesterUtil.printWarningMessage( Constants.PRG_NAME, "unknown value [" + type_str
961                         + "] for [overview_placement_type]" );
962             }
963         }
964         else if ( key.equals( "node_label_direction" ) ) {
965             final String type_str = ( ( String ) st.nextElement() ).trim();
966             if ( type_str.equalsIgnoreCase( NODE_LABEL_DIRECTION.HORIZONTAL.toString() ) ) {
967                 setNodeLabelDirection( NODE_LABEL_DIRECTION.HORIZONTAL );
968             }
969             else if ( type_str.equalsIgnoreCase( NODE_LABEL_DIRECTION.RADIAL.toString() ) ) {
970                 setNodeLabelDirection( NODE_LABEL_DIRECTION.RADIAL );
971             }
972             else {
973                 setNodeLabelDirection( NODE_LABEL_DIRECTION.HORIZONTAL );
974                 ForesterUtil.printWarningMessage( Constants.PRG_NAME, "unknown value [" + type_str
975                         + "] for [node_label_direction]" );
976             }
977         }
978         else if ( key.equals( "branch_length_value_digits" ) ) {
979             final short i = parseShort( ( ( String ) st.nextElement() ).trim() );
980             if ( i >= 0 ) {
981                 setNumberOfDigitsAfterCommaForBranchLengthValue( i );
982             }
983             else {
984                 ForesterUtil.printWarningMessage( Constants.PRG_NAME, "illegal value [" + i
985                         + "] for [branch_length_value_digits]" );
986             }
987         }
988         else if ( key.equals( "confidence_value_digits" ) ) {
989             final short i = parseShort( ( ( String ) st.nextElement() ).trim() );
990             if ( i >= 0 ) {
991                 setNumberOfDigitsAfterCommaForConfidenceValues( i );
992             }
993             else {
994                 ForesterUtil.printWarningMessage( Constants.PRG_NAME, "illegal value [" + i
995                         + "] for [confidence_value_digits]" );
996             }
997         }
998         else if ( key.equals( "allow_editing" ) ) {
999             setEditable( parseBoolean( ( String ) st.nextElement() ) );
1000         }
1001         else if ( key.equals( "display_sequence_relations" ) ) {
1002             setDisplaySequenceRelations( parseBoolean( ( String ) st.nextElement() ) );
1003         }
1004         else if ( key.equals( "replace_underscores_in_nh_parsing" ) ) {
1005             final boolean r = parseBoolean( ( String ) st.nextElement() );
1006             if ( r && isExtractPfamTaxonomyCodesInNhParsing() ) {
1007                 ForesterUtil
1008                         .printWarningMessage( Constants.PRG_NAME,
1009                                               "attempt to extract taxonomies and replace underscores at the same time" );
1010             }
1011             else {
1012                 setReplaceUnderscoresInNhParsing( r );
1013             }
1014         }
1015         else if ( key.equals( "extract_taxonomy_codes_in_nh_parsing" ) ) {
1016             final boolean e = parseBoolean( ( String ) st.nextElement() );
1017             if ( e && isReplaceUnderscoresInNhParsing() ) {
1018                 ForesterUtil
1019                         .printWarningMessage( Constants.PRG_NAME,
1020                                               "attempt to extract taxonomies and replace underscores at the same time" );
1021             }
1022             else {
1023                 setExtractPfamTaxonomyCodesInNhParsing( e );
1024             }
1025         }
1026         else if ( key.equals( "internal_labels_are_confidence_values" ) ) {
1027             setInternalNumberAreConfidenceForNhParsing( parseBoolean( ( String ) st.nextElement() ) );
1028         }
1029         else if ( key.equals( "gui_background_color" ) ) {
1030             _gui_background_color = Color.decode( ( String ) st.nextElement() );
1031         }
1032         else if ( key.equals( "gui_checkbox_text_color" ) ) {
1033             _gui_checkbox_text_color = Color.decode( ( String ) st.nextElement() );
1034         }
1035         else if ( key.equals( "gui_checkbox_and_button_active_color" ) ) {
1036             _gui_checkbox_and_button_active_color = Color.decode( ( String ) st.nextElement() );
1037         }
1038         else if ( key.equals( "gui_button_text_color" ) ) {
1039             _gui_button_text_color = Color.decode( ( String ) st.nextElement() );
1040         }
1041         else if ( key.equals( "gui_button_background_color" ) ) {
1042             _gui_button_background_color = Color.decode( ( String ) st.nextElement() );
1043         }
1044         else if ( key.equals( "gui_menu_background_color" ) ) {
1045             _gui_menu_background_color = Color.decode( ( String ) st.nextElement() );
1046         }
1047         else if ( key.equals( "gui_menu_text_color" ) ) {
1048             _gui_menu_text_color = Color.decode( ( String ) st.nextElement() );
1049         }
1050         else if ( key.equals( "gui_button_border_color" ) ) {
1051             _gui_button_border_color = Color.decode( ( String ) st.nextElement() );
1052         }
1053         else if ( key.equals( "domain_structure_font_color" ) ) {
1054             _domain_structure_font_color = Color.decode( ( String ) st.nextElement() );
1055         }
1056         else if ( key.equals( "domain_structure_base_color" ) ) {
1057             _domain_structure_base_color = Color.decode( ( String ) st.nextElement() );
1058         }
1059         else if ( st.countTokens() >= 2 ) { // counts the tokens that are not
1060             // yet retrieved!
1061             int key_index = -1;
1062             if ( key.equals( "use_real_br_lengths" ) || key.equals( "phylogram" ) ) {
1063                 key_index = Configuration.display_as_phylogram;
1064                 if ( key.equals( "use_real_br_lengths" ) ) {
1065                     ForesterUtil
1066                             .printWarningMessage( Constants.PRG_NAME,
1067                                                   "configuration key [use_real_br_lengths] is deprecated, use [phylogram] instead" );
1068                 }
1069             }
1070             else if ( key.equals( "rollover" ) ) {
1071                 key_index = Configuration.node_data_popup;
1072             }
1073             else if ( key.equals( "color_according_to_species" ) ) {
1074                 key_index = Configuration.color_according_to_species;
1075             }
1076             else if ( key.equals( "show_node_names" ) ) {
1077                 key_index = Configuration.show_node_names;
1078             }
1079             else if ( key.equals( "show_taxonomy" ) || key.equals( "show_taxonomy_code" ) ) {
1080                 key_index = Configuration.show_tax_code;
1081                 if ( key.equals( "show_taxonomy" ) ) {
1082                     ForesterUtil
1083                             .printWarningMessage( Constants.PRG_NAME,
1084                                                   "configuration key [show_taxonomy] is deprecated, use [show_taxonomy_code] instead" );
1085                 }
1086             }
1087             else if ( key.equals( "write_br_length_values" ) ) {
1088                 ForesterUtil.printWarningMessage( Constants.PRG_NAME,
1089                                                   "configuration key [write_br_length_values] is deprecated" );
1090                 key_index = DEPRECATED;
1091             }
1092             else if ( key.equals( "write_bootstrap_values" ) || key.equals( "write_confidence_values" ) ) {
1093                 key_index = Configuration.write_confidence_values;
1094                 if ( key.equals( "write_bootstrap_values" ) ) {
1095                     ForesterUtil
1096                             .printWarningMessage( Constants.PRG_NAME,
1097                                                   "configuration key [write_bootstrap_values] is deprecated, use [write_confidence_values] instead" );
1098                 }
1099             }
1100             else if ( key.equals( "write_events" ) || key.equals( "write_dup_spec" ) ) {
1101                 key_index = Configuration.write_events;
1102                 if ( key.equals( "write_dup_spec" ) ) {
1103                     ForesterUtil
1104                             .printWarningMessage( Constants.PRG_NAME,
1105                                                   "configuration key [write_dup_spec] is deprecated, use [write_events] instead" );
1106                 }
1107             }
1108             else if ( key.equals( "color_branches" ) ) {
1109                 key_index = Configuration.color_branches;
1110             }
1111             else if ( key.equals( "width_branches" ) ) {
1112                 key_index = Configuration.width_branches;
1113             }
1114             else if ( key.equals( "color_orthologous" ) ) {
1115                 ForesterUtil.printWarningMessage( Constants.PRG_NAME,
1116                                                   "configuration key [color_orthologous] is deprecated" );
1117             }
1118             else if ( key.equals( "color_subtree_neighbors" ) ) {
1119                 ForesterUtil.printWarningMessage( Constants.PRG_NAME,
1120                                                   "configuration key [color_subtree_neighbors] is deprecated" );
1121             }
1122             else if ( key.equals( "color_super_orthologous" ) ) {
1123                 ForesterUtil.printWarningMessage( Constants.PRG_NAME,
1124                                                   "configuration key [color_super_orthologous] is deprecated" );
1125             }
1126             else if ( key.equals( "mark_nodes_with_box" ) ) {
1127                 ForesterUtil.printWarningMessage( Constants.PRG_NAME,
1128                                                   "configuration key [mark_nodes_with_box] is deprecated" );
1129                 key_index = DEPRECATED;
1130             }
1131             else if ( key.equals( "show_domain_architectures" ) ) {
1132                 key_index = Configuration.show_domain_architectures;
1133             }
1134             else if ( key.equals( "show_annotations" ) ) {
1135                 key_index = Configuration.show_annotation;
1136             }
1137             else if ( key.equals( "show_binary_characters" ) ) {
1138                 key_index = Configuration.show_binary_characters;
1139             }
1140             else if ( key.equals( "show_binary_character_counts" ) ) {
1141                 key_index = Configuration.show_binary_character_counts;
1142             }
1143             else if ( key.equals( "show_gene_names" ) ) {
1144                 key_index = Configuration.show_gene_names;
1145             }
1146             else if ( key.equals( "show_gene_symbols" ) ) {
1147                 key_index = Configuration.show_gene_symbols;
1148             }
1149             else if ( key.equals( "show_sequence_acc" ) ) {
1150                 key_index = Configuration.show_sequence_acc;
1151             }
1152             else if ( key.equals( "show_node_ids" ) ) {
1153                 ForesterUtil
1154                         .printWarningMessage( Constants.PRG_NAME, "configuration key [show_node_ids] is deprecated" );
1155                 key_index = DEPRECATED;
1156             }
1157             else if ( key.equals( "display_internal_data" ) ) {
1158                 key_index = Configuration.display_internal_data;
1159             }
1160             else if ( key.equals( "dynamically_hide_data" ) ) {
1161                 key_index = Configuration.dynamically_hide_data;
1162             }
1163             else if ( key.equals( "show_taxonomy_names" ) ) {
1164                 ForesterUtil.printWarningMessage( Constants.PRG_NAME,
1165                                                   "configuration key [show_taxonomy_names] is deprecated" );
1166                 key_index = DEPRECATED;
1167             }
1168             else if ( key.equals( "show_taxonomy_scientific_names" ) ) {
1169                 key_index = Configuration.show_taxonomy_scientific_names;
1170             }
1171             else if ( key.equals( "show_taxonomy_common_names" ) ) {
1172                 key_index = Configuration.show_taxonomy_common_names;
1173             }
1174             else if ( key.equals( "show_taxonomy_images" ) ) {
1175                 key_index = Configuration.show_taxonomy_images;
1176             }
1177             else if ( key.equals( "color_according_to_annotation" ) ) {
1178                 key_index = Configuration.color_according_to_annotation;
1179             }
1180             else if ( key.equals( "show_property" ) ) {
1181                 key_index = Configuration.show_property;
1182             }
1183             else if ( key.equals( "show_vector_data" ) ) {
1184                 key_index = Configuration.show_vector_data;
1185             }
1186             else if ( key.equals( "show_relation_confidence" ) ) {
1187                 key_index = Configuration.show_relation_confidence;
1188             }
1189             // If we've found the key, set the values
1190             if ( key_index >= 0 ) {
1191                 display_options[ key_index ][ 1 ] = ( String ) st.nextElement();
1192                 display_options[ key_index ][ 2 ] = ( String ) st.nextElement();
1193                 // otherwise, keep looking
1194             }
1195             else {
1196                 if ( key_index == DEPRECATED ) {
1197                     // Deprecated.
1198                 }
1199                 else if ( key.equals( "click_to" ) ) {
1200                     final String click_to_name = ( String ) st.nextElement();
1201                     key_index = getClickToIndex( click_to_name );
1202                     if ( key_index >= 0 ) {
1203                         clickto_options[ key_index ][ 1 ] = ( String ) st.nextElement();
1204                     }
1205                     else if ( key_index == DEPRECATED ) {
1206                         // Deprecated.
1207                     }
1208                     else {
1209                         ForesterUtil.printWarningMessage( Constants.PRG_NAME, "unknown click-to option: "
1210                                 + click_to_name );
1211                     }
1212                 }
1213                 else if ( key.equals( "species_color" ) ) {
1214                     getSpeciesColors().put( ( String ) st.nextElement(), Color.decode( ( String ) st.nextElement() ) );
1215                 }
1216                 else if ( key.equals( "domain_color" ) ) {
1217                     getDomainColors().put( ( String ) st.nextElement(), Color.decode( ( String ) st.nextElement() ) );
1218                 }
1219                 else if ( key.equals( "annotation_color" ) ) {
1220                     getAnnotationColors()
1221                             .put( ( String ) st.nextElement(), Color.decode( ( String ) st.nextElement() ) );
1222                 }
1223                 else if ( key.equals( "function_color" ) ) {
1224                     ForesterUtil.printWarningMessage( Constants.PRG_NAME,
1225                                                       "configuration key [function_color] is deprecated" );
1226                 }
1227                 else if ( key.equals( DISPLAY_COLOR_KEY ) ) {
1228                     getDisplayColors().put( ( String ) st.nextElement(), Color.decode( ( String ) st.nextElement() ) );
1229                 }
1230                 else if ( key.equals( WEB_LINK_KEY ) ) {
1231                     if ( st.countTokens() == 3 ) {
1232                         createWebLink( ( String ) st.nextElement(),
1233                                        ( String ) st.nextElement(),
1234                                        ( String ) st.nextElement() );
1235                     }
1236                     else {
1237                         ForesterUtil.printWarningMessage( Constants.PRG_NAME,
1238                                                           "illegal format in configuration file for key [" + key + "]" );
1239                     }
1240                 }
1241                 else {
1242                     ForesterUtil.printWarningMessage( Constants.PRG_NAME, "unknown configuration key [" + key
1243                             + "] in: " + config_filename );
1244                 }
1245             }
1246         }
1247         else {
1248             ForesterUtil.printWarningMessage( Constants.PRG_NAME, "unknown configuration key [" + key + "] in: "
1249                     + config_filename );
1250         }
1251     }
1252
1253     private void setMinConfidenceValue( final double min_confidence_value ) {
1254         _min_confidence_value = min_confidence_value;
1255     }
1256
1257     void setNodeLabelDirection( final NODE_LABEL_DIRECTION node_label_direction ) {
1258         _node_label_direction = node_label_direction;
1259     }
1260
1261     private void setNumberOfDigitsAfterCommaForBranchLengthValue( final short _number_of_digits_after_comma_for_branch_length_values ) {
1262         this._number_of_digits_after_comma_for_branch_length_values = _number_of_digits_after_comma_for_branch_length_values;
1263     }
1264
1265     private void setNumberOfDigitsAfterCommaForConfidenceValues( final short _number_of_digits_after_comma_for_confidence_values ) {
1266         this._number_of_digits_after_comma_for_confidence_values = _number_of_digits_after_comma_for_confidence_values;
1267     }
1268
1269     private void setOvMaxHeight( final short ov_max_height ) {
1270         _ov_max_height = ov_max_height;
1271     }
1272
1273     private void setOvMaxWidth( final short ov_max_width ) {
1274         _ov_max_width = ov_max_width;
1275     }
1276
1277     private void setOvPlacement( final OVERVIEW_PLACEMENT_TYPE ov_placement ) {
1278         _ov_placement = ov_placement;
1279     }
1280
1281     void setPhylogenyGraphicsType( final PHYLOGENY_GRAPHICS_TYPE phylogeny_graphics_type ) {
1282         _phylogeny_graphics_type = phylogeny_graphics_type;
1283     }
1284
1285     private void setPrintLineWidth( final float print_line_width ) {
1286         _print_line_width = print_line_width;
1287     }
1288
1289     private void setReplaceUnderscoresInNhParsing( final boolean nh_parsing_replace_underscores ) {
1290         _nh_parsing_replace_underscores = nh_parsing_replace_underscores;
1291     }
1292
1293     private void setShowBranchLengthValues( final boolean show_branch_length_values ) {
1294         _show_branch_length_values = show_branch_length_values;
1295     }
1296
1297     private void setShowOverview( final boolean show_overview ) {
1298         _show_overview = show_overview;
1299     }
1300
1301     private void setShowScale( final boolean show_scale ) {
1302         _show_scale = show_scale;
1303     }
1304
1305     private void setValidatePhyloXmlAgainstSchema( final boolean validate_against_phyloxml_xsd_schema ) {
1306         _validate_against_phyloxml_xsd_schema = validate_against_phyloxml_xsd_schema;
1307     }
1308
1309     void setWebLinks( final SortedMap<String, WebLink> weblinks ) {
1310         _weblinks = weblinks;
1311     }
1312
1313     static String getDefaultFontFamilyName() {
1314         return DEFAULT_FONT_FAMILY;
1315     }
1316
1317     static enum TRIPLET {
1318         TRUE, FALSE, UNKNOWN
1319     }
1320
1321     public Color getDomainStructureFontColor() {
1322         return _domain_structure_font_color;
1323     }
1324
1325     public Color getDomainStructureBaseColor() {
1326         return _domain_structure_base_color;
1327     }
1328
1329     public boolean isColorLabelsSameAsParentBranch() {
1330         return _color_labels_same_as_parent_branch;
1331     }
1332
1333     public boolean isShowDomainLabels() {
1334         return _show_domain_labels;
1335     }
1336
1337     public boolean isAbbreviateScientificTaxonNames() {
1338         return _abbreviate_scientific_names;
1339     }
1340 }