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