new UI types?
[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, SYSTEM, 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     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 ) {
589             if ( Util.isMac() && Util.isJava15() ) {
590                 _ui = UI.NATIVE;
591             }
592         }
593         return _ui == UI.NATIVE;
594     }
595
596     /**
597      * Only used by ArchaeoptryxE.
598      *
599      */
600     boolean isUseTabbedDisplay() {
601         return _use_tabbed_display;
602     }
603
604     boolean isValidatePhyloXmlAgainstSchema() {
605         return _validate_against_phyloxml_xsd_schema;
606     }
607
608     private boolean parseBoolean( final String str ) {
609         final String my_str = str.trim().toLowerCase();
610         if ( my_str.equals( "yes" ) || my_str.equals( "true" ) ) {
611             return true;
612         }
613         else if ( my_str.equals( "no" ) || my_str.equals( "false" ) ) {
614             return false;
615         }
616         else {
617             ForesterUtil.printWarningMessage( Constants.PRG_NAME, "could not parse boolean value from [" + str + "]" );
618             return false;
619         }
620     }
621
622     private double parseDouble( final String str ) {
623         double d = 0.0;
624         try {
625             d = Double.parseDouble( str );
626         }
627         catch ( final Exception e ) {
628             ForesterUtil.printWarningMessage( Constants.PRG_NAME, "could not parse double from [" + str + "]" );
629             d = 0.0;
630         }
631         return d;
632     }
633
634     private float parseFloat( final String str ) {
635         float f = 0.0f;
636         try {
637             f = Float.parseFloat( str );
638         }
639         catch ( final Exception e ) {
640             ForesterUtil.printWarningMessage( Constants.PRG_NAME, "could not parse float from [" + str + "]" );
641             f = 0.0f;
642         }
643         return f;
644     }
645
646     private int parseInt( final String str ) {
647         int i = -1;
648         try {
649             i = Integer.parseInt( str );
650         }
651         catch ( final Exception e ) {
652             ForesterUtil.printWarningMessage( Constants.PRG_NAME, "could not parse integer from [" + str + "]" );
653             i = -1;
654         }
655         return i;
656     }
657
658     private short parseShort( final String str ) {
659         short i = -1;
660         try {
661             i = Short.parseShort( str );
662         }
663         catch ( final Exception e ) {
664             ForesterUtil.printWarningMessage( Constants.PRG_NAME, "could not parse short from [" + str + "]" );
665             i = -1;
666         }
667         return i;
668     }
669
670     private void processFontFamily( final StringTokenizer st ) {
671         setBaseFontFamilyName( "" );
672         final String font_str = ( ( String ) st.nextElement() ).trim();
673         final String[] fonts = font_str.split( ",+" );
674         for( String font : fonts ) {
675             font = font.replace( '_', ' ' ).trim();
676             if ( Arrays.binarySearch( Util.getAvailableFontFamiliesSorted(), font ) >= 0 ) {
677                 setBaseFontFamilyName( font );
678                 break;
679             }
680         }
681     }
682
683     /**
684      * read each line of config file, process non-comment lines
685      * @throws IOException 
686      */
687     private void readConfig( final BufferedReader conf_in ) throws IOException {
688         String line;
689         do {
690             line = conf_in.readLine();
691             if ( line != null ) {
692                 line = line.trim();
693                 // skip comments and blank lines
694                 if ( !line.startsWith( "#" ) && ( !ForesterUtil.isEmpty( line ) ) ) {
695                     // convert runs of spaces to tabs
696                     line = line.replaceAll( "\\s+", "\t" );
697                     final StringTokenizer st = new StringTokenizer( line, "\t" );
698                     setKeyValue( st );
699                 }
700             }
701         } while ( line != null );
702     }
703
704     private void setAntialiasScreen( final boolean antialias_screen ) {
705         _antialias_screen = antialias_screen;
706     }
707
708     public void setBackgroundColorGradient( final boolean background_color_gradient ) {
709         _background_color_gradient = background_color_gradient;
710     }
711
712     private void setBaseFontFamilyName( final String base_font_family_name ) {
713         _base_font_family_name = base_font_family_name;
714     }
715
716     private void setBaseFontSize( final int base_font_size ) {
717         _base_font_size = base_font_size;
718     }
719
720     private void setShowDomainLabels( final boolean show_domain_labels ) {
721         _show_domain_labels = show_domain_labels;
722     }
723
724     private void setAbbreviateScientificTaxonNames( final boolean abbreviate_scientific_names ) {
725         _abbreviate_scientific_names = abbreviate_scientific_names;
726     }
727
728     private void setColorLabelsSameAsParentBranch( final boolean color_labels_same_as_parent_branch ) {
729         _color_labels_same_as_parent_branch = color_labels_same_as_parent_branch;
730     }
731
732     private void setCladogramType( final CLADOGRAM_TYPE cladogram_type ) {
733         _cladogram_type = cladogram_type;
734     }
735
736     void setDisplayColors( final SortedMap<String, Color> display_colors ) {
737         _display_colors = display_colors;
738     }
739
740     private void setDisplaySequenceRelations( final boolean display_sequence_relations ) {
741         _display_sequence_relations = display_sequence_relations;
742     }
743
744     private void setEditable( final boolean editable ) {
745         _editable = editable;
746     }
747
748     private void setExtractPfamTaxonomyCodesInNhParsing( final boolean nh_parsing_extract_pfam_taxonomy_codes ) {
749         _nh_parsing_extract_pfam_taxonomy_codes = nh_parsing_extract_pfam_taxonomy_codes;
750     }
751
752     private void setGraphicsExportX( final int graphics_export_x ) {
753         _graphics_export_x = graphics_export_x;
754     }
755
756     private void setGraphicsExportY( final int graphics_export_y ) {
757         _graphics_export_y = graphics_export_y;
758     }
759
760     private void setDefaultBootstrapSamples( final int default_bootstrap_samples ) {
761         _default_bootstrap_samples = default_bootstrap_samples;
762     }
763
764     private void setInternalNumberAreConfidenceForNhParsing( final boolean internal_number_are_confidence_for_nh_parsing ) {
765         _internal_number_are_confidence_for_nh_parsing = internal_number_are_confidence_for_nh_parsing;
766     }
767
768     /**
769      * Set a key-value(s) tuple
770      */
771     private void setKeyValue( final StringTokenizer st ) {
772         String key = ( String ) st.nextElement();
773         key = key.replace( ':', ' ' );
774         key = key.trim();
775         key = key.toLowerCase();
776         // Handle single value settings first:
777         if ( key.equals( "default_click_to" ) ) {
778             final String clickto_name = ( String ) st.nextElement();
779             default_clickto = getClickToIndex( clickto_name );
780             if ( default_clickto == -1 ) {
781                 ForesterUtil.printWarningMessage( Constants.PRG_NAME, "invalid value [" + clickto_name
782                         + "] for [default_click_to]" );
783                 default_clickto = 0;
784             }
785             else if ( default_clickto == DEPRECATED ) {
786                 // Deprecated.
787             }
788         }
789         else if ( key.equals( "native_ui" ) ) {
790             final String my_str = ( ( String ) st.nextElement() ).trim().toLowerCase();
791             if ( my_str.equals( "yes" ) || my_str.equals( "true" ) ) {
792                 _ui = UI.NATIVE;
793             }
794             else if ( my_str.equals( "no" ) || my_str.equals( "false" ) ) {
795                 _ui = UI.SYSTEM;
796             }
797             else if ( my_str.equals( "?" ) ) {
798                 _ui = UI.UNKNOWN;
799             }
800             else {
801                 ForesterUtil.printWarningMessage( Constants.PRG_NAME, "could not parse yes/no/? value from [" + my_str
802                         + "]" );
803                 _ui = UI.UNKNOWN;
804             }
805         }
806         else if ( key.equals( VALIDATE_AGAINST_PHYLOXML_XSD_SCHEMA ) ) {
807             setValidatePhyloXmlAgainstSchema( parseBoolean( ( String ) st.nextElement() ) );
808         }
809         else if ( key.equals( "antialias_screen" ) ) {
810             setAntialiasScreen( parseBoolean( ( String ) st.nextElement() ) );
811         }
812         else if ( key.equals( "phylogeny_graphics_type" ) ) {
813             final String type_str = ( ( String ) st.nextElement() ).trim();
814             if ( type_str.equalsIgnoreCase( PHYLOGENY_GRAPHICS_TYPE.CONVEX.toString() ) ) {
815                 setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CONVEX );
816             }
817             else if ( type_str.equalsIgnoreCase( PHYLOGENY_GRAPHICS_TYPE.CURVED.toString() ) ) {
818                 setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CURVED );
819             }
820             else if ( type_str.equalsIgnoreCase( PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE.toString() ) ) {
821                 setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE );
822             }
823             else if ( type_str.equalsIgnoreCase( PHYLOGENY_GRAPHICS_TYPE.ROUNDED.toString() ) ) {
824                 setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.ROUNDED );
825             }
826             else if ( type_str.equalsIgnoreCase( PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR.toString() ) ) {
827                 setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR );
828             }
829             else if ( type_str.equalsIgnoreCase( PHYLOGENY_GRAPHICS_TYPE.TRIANGULAR.toString() ) ) {
830                 setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.TRIANGULAR );
831             }
832             else if ( type_str.equalsIgnoreCase( PHYLOGENY_GRAPHICS_TYPE.UNROOTED.toString() ) ) {
833                 setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.UNROOTED );
834             }
835             else if ( type_str.equalsIgnoreCase( PHYLOGENY_GRAPHICS_TYPE.CIRCULAR.toString() ) ) {
836                 setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CIRCULAR );
837             }
838             else {
839                 setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR );
840                 ForesterUtil.printWarningMessage( Constants.PRG_NAME, "unknown value [" + type_str
841                         + "] for [phylogeny_graphics_type]" );
842             }
843         }
844         else if ( key.equals( "min_confidence_value" ) ) {
845             final String mcv_str = ( ( String ) st.nextElement() ).trim();
846             final double d = parseDouble( mcv_str );
847             setMinConfidenceValue( d );
848         }
849         else if ( key.equals( "font_family" ) ) {
850             processFontFamily( st );
851         }
852         else if ( key.equals( "font_size" ) ) {
853             final String size_str = ( ( String ) st.nextElement() ).trim();
854             final int i = parseInt( size_str );
855             setBaseFontSize( i );
856         }
857         else if ( key.equals( "graphics_export_x" ) ) {
858             final String str = ( ( String ) st.nextElement() ).trim();
859             final int i = parseInt( str );
860             setGraphicsExportX( i );
861         }
862         else if ( key.equals( "graphics_export_y" ) ) {
863             final String str = ( ( String ) st.nextElement() ).trim();
864             final int i = parseInt( str );
865             setGraphicsExportY( i );
866         }
867         else if ( key.equals( "pdf_export_line_width" ) ) {
868             final String str = ( ( String ) st.nextElement() ).trim();
869             final float f = parseFloat( str );
870             if ( f > 0 ) {
871                 setPrintLineWidth( f );
872             }
873             else {
874                 ForesterUtil.printWarningMessage( Constants.PRG_NAME,
875                                                   "value for [pdf_export_line_width] cannot be zero or negative" );
876             }
877         }
878         else if ( key.equals( "default_number_of_bootstrap_resamples" ) ) {
879             final String str = ( ( String ) st.nextElement() ).trim();
880             final int i = parseInt( str );
881             if ( i >= 0 ) {
882                 setDefaultBootstrapSamples( i );
883             }
884             else {
885                 ForesterUtil
886                         .printWarningMessage( Constants.PRG_NAME,
887                                               "value for [default_number_of_bootstrap_resamples] cannot be negative" );
888             }
889         }
890         else if ( key.equals( "show_scale" ) ) {
891             setShowScale( parseBoolean( ( String ) st.nextElement() ) );
892         }
893         else if ( key.equals( "show_overview" ) ) {
894             setShowOverview( parseBoolean( ( String ) st.nextElement() ) );
895         }
896         else if ( key.equals( "show_branch_length_values" ) ) {
897             setShowBranchLengthValues( parseBoolean( ( String ) st.nextElement() ) );
898         }
899         else if ( key.equals( "background_gradient" ) ) {
900             setBackgroundColorGradient( parseBoolean( ( String ) st.nextElement() ) );
901         }
902         else if ( key.equals( "color_labels_same_as_branch_length_values" ) ) {
903             setColorLabelsSameAsParentBranch( parseBoolean( ( String ) st.nextElement() ) );
904         }
905         else if ( key.equals( "show_domain_labels" ) ) {
906             setShowDomainLabels( parseBoolean( ( String ) st.nextElement() ) );
907         }
908         else if ( key.equals( "abbreviate_scientific_names" ) ) {
909             setAbbreviateScientificTaxonNames( parseBoolean( ( String ) st.nextElement() ) );
910         }
911         else if ( key.equals( "cladogram_type" ) ) {
912             final String type_str = ( ( String ) st.nextElement() ).trim();
913             if ( type_str.equalsIgnoreCase( Options.CLADOGRAM_TYPE.NON_LINED_UP.toString() ) ) {
914                 setCladogramType( Options.CLADOGRAM_TYPE.NON_LINED_UP );
915             }
916             else if ( type_str.equalsIgnoreCase( Options.CLADOGRAM_TYPE.EXT_NODE_SUM_DEP.toString() ) ) {
917                 setCladogramType( Options.CLADOGRAM_TYPE.EXT_NODE_SUM_DEP );
918             }
919             else if ( type_str.equalsIgnoreCase( Options.CLADOGRAM_TYPE.TOTAL_NODE_SUM_DEP.toString() ) ) {
920                 setCladogramType( Options.CLADOGRAM_TYPE.TOTAL_NODE_SUM_DEP );
921             }
922             else {
923                 ForesterUtil.printWarningMessage( Constants.PRG_NAME, "unknown value [" + type_str
924                         + "] for [cladogram_type]" );
925             }
926         }
927         else if ( key.equals( "non_lined_up_cladogram" ) ) {
928             ForesterUtil
929                     .printWarningMessage( Constants.PRG_NAME,
930                                           "configuration key [non_lined_up_cladogram] is deprecated, use [cladogram_type] instead" );
931         }
932         else if ( key.equals( "hide_controls_and_menus" ) ) {
933             _hide_controls_and_menus = parseBoolean( ( String ) st.nextElement() );
934         }
935         else if ( key.equals( "use_tabbed_display" ) ) {
936             _use_tabbed_display = parseBoolean( ( String ) st.nextElement() );
937         }
938         else if ( key.equals( "overview_width" ) ) {
939             final short i = parseShort( ( ( String ) st.nextElement() ).trim() );
940             setOvMaxWidth( i );
941         }
942         else if ( key.equals( "overview_height" ) ) {
943             final short i = parseShort( ( ( String ) st.nextElement() ).trim() );
944             setOvMaxHeight( i );
945         }
946         else if ( key.equals( "overview_placement_type" ) ) {
947             final String type_str = ( ( String ) st.nextElement() ).trim();
948             if ( type_str.equalsIgnoreCase( OVERVIEW_PLACEMENT_TYPE.UPPER_LEFT.toTag() ) ) {
949                 setOvPlacement( OVERVIEW_PLACEMENT_TYPE.UPPER_LEFT );
950             }
951             else if ( type_str.equalsIgnoreCase( OVERVIEW_PLACEMENT_TYPE.UPPER_RIGHT.toTag() ) ) {
952                 setOvPlacement( OVERVIEW_PLACEMENT_TYPE.UPPER_RIGHT );
953             }
954             else if ( type_str.equalsIgnoreCase( OVERVIEW_PLACEMENT_TYPE.LOWER_LEFT.toTag() ) ) {
955                 setOvPlacement( OVERVIEW_PLACEMENT_TYPE.LOWER_LEFT );
956             }
957             else if ( type_str.equalsIgnoreCase( OVERVIEW_PLACEMENT_TYPE.LOWER_RIGHT.toTag() ) ) {
958                 setOvPlacement( OVERVIEW_PLACEMENT_TYPE.LOWER_RIGHT );
959             }
960             else {
961                 setOvPlacement( OVERVIEW_PLACEMENT_TYPE.UPPER_LEFT );
962                 ForesterUtil.printWarningMessage( Constants.PRG_NAME, "unknown value [" + type_str
963                         + "] for [overview_placement_type]" );
964             }
965         }
966         else if ( key.equals( "node_label_direction" ) ) {
967             final String type_str = ( ( String ) st.nextElement() ).trim();
968             if ( type_str.equalsIgnoreCase( NODE_LABEL_DIRECTION.HORIZONTAL.toString() ) ) {
969                 setNodeLabelDirection( NODE_LABEL_DIRECTION.HORIZONTAL );
970             }
971             else if ( type_str.equalsIgnoreCase( NODE_LABEL_DIRECTION.RADIAL.toString() ) ) {
972                 setNodeLabelDirection( NODE_LABEL_DIRECTION.RADIAL );
973             }
974             else {
975                 setNodeLabelDirection( NODE_LABEL_DIRECTION.HORIZONTAL );
976                 ForesterUtil.printWarningMessage( Constants.PRG_NAME, "unknown value [" + type_str
977                         + "] for [node_label_direction]" );
978             }
979         }
980         else if ( key.equals( "branch_length_value_digits" ) ) {
981             final short i = parseShort( ( ( String ) st.nextElement() ).trim() );
982             if ( i >= 0 ) {
983                 setNumberOfDigitsAfterCommaForBranchLengthValue( i );
984             }
985             else {
986                 ForesterUtil.printWarningMessage( Constants.PRG_NAME, "illegal value [" + i
987                         + "] for [branch_length_value_digits]" );
988             }
989         }
990         else if ( key.equals( "confidence_value_digits" ) ) {
991             final short i = parseShort( ( ( String ) st.nextElement() ).trim() );
992             if ( i >= 0 ) {
993                 setNumberOfDigitsAfterCommaForConfidenceValues( i );
994             }
995             else {
996                 ForesterUtil.printWarningMessage( Constants.PRG_NAME, "illegal value [" + i
997                         + "] for [confidence_value_digits]" );
998             }
999         }
1000         else if ( key.equals( "allow_editing" ) ) {
1001             setEditable( parseBoolean( ( String ) st.nextElement() ) );
1002         }
1003         else if ( key.equals( "display_sequence_relations" ) ) {
1004             setDisplaySequenceRelations( parseBoolean( ( String ) st.nextElement() ) );
1005         }
1006         else if ( key.equals( "replace_underscores_in_nh_parsing" ) ) {
1007             final boolean r = parseBoolean( ( String ) st.nextElement() );
1008             if ( r && isExtractPfamTaxonomyCodesInNhParsing() ) {
1009                 ForesterUtil
1010                         .printWarningMessage( Constants.PRG_NAME,
1011                                               "attempt to extract taxonomies and replace underscores at the same time" );
1012             }
1013             else {
1014                 setReplaceUnderscoresInNhParsing( r );
1015             }
1016         }
1017         else if ( key.equals( "extract_taxonomy_codes_in_nh_parsing" ) ) {
1018             final boolean e = parseBoolean( ( String ) st.nextElement() );
1019             if ( e && isReplaceUnderscoresInNhParsing() ) {
1020                 ForesterUtil
1021                         .printWarningMessage( Constants.PRG_NAME,
1022                                               "attempt to extract taxonomies and replace underscores at the same time" );
1023             }
1024             else {
1025                 setExtractPfamTaxonomyCodesInNhParsing( e );
1026             }
1027         }
1028         else if ( key.equals( "internal_labels_are_confidence_values" ) ) {
1029             setInternalNumberAreConfidenceForNhParsing( parseBoolean( ( String ) st.nextElement() ) );
1030         }
1031         else if ( key.equals( "gui_background_color" ) ) {
1032             _gui_background_color = Color.decode( ( String ) st.nextElement() );
1033         }
1034         else if ( key.equals( "gui_checkbox_text_color" ) ) {
1035             _gui_checkbox_text_color = Color.decode( ( String ) st.nextElement() );
1036         }
1037         else if ( key.equals( "gui_checkbox_and_button_active_color" ) ) {
1038             _gui_checkbox_and_button_active_color = Color.decode( ( String ) st.nextElement() );
1039         }
1040         else if ( key.equals( "gui_button_text_color" ) ) {
1041             _gui_button_text_color = Color.decode( ( String ) st.nextElement() );
1042         }
1043         else if ( key.equals( "gui_button_background_color" ) ) {
1044             _gui_button_background_color = Color.decode( ( String ) st.nextElement() );
1045         }
1046         else if ( key.equals( "gui_menu_background_color" ) ) {
1047             _gui_menu_background_color = Color.decode( ( String ) st.nextElement() );
1048         }
1049         else if ( key.equals( "gui_menu_text_color" ) ) {
1050             _gui_menu_text_color = Color.decode( ( String ) st.nextElement() );
1051         }
1052         else if ( key.equals( "gui_button_border_color" ) ) {
1053             _gui_button_border_color = Color.decode( ( String ) st.nextElement() );
1054         }
1055         else if ( key.equals( "domain_structure_font_color" ) ) {
1056             _domain_structure_font_color = Color.decode( ( String ) st.nextElement() );
1057         }
1058         else if ( key.equals( "domain_structure_base_color" ) ) {
1059             _domain_structure_base_color = Color.decode( ( String ) st.nextElement() );
1060         }
1061         else if ( st.countTokens() >= 2 ) { // counts the tokens that are not
1062             // yet retrieved!
1063             int key_index = -1;
1064             if ( key.equals( "use_real_br_lengths" ) || key.equals( "phylogram" ) ) {
1065                 key_index = Configuration.display_as_phylogram;
1066                 if ( key.equals( "use_real_br_lengths" ) ) {
1067                     ForesterUtil
1068                             .printWarningMessage( Constants.PRG_NAME,
1069                                                   "configuration key [use_real_br_lengths] is deprecated, use [phylogram] instead" );
1070                 }
1071             }
1072             else if ( key.equals( "rollover" ) ) {
1073                 key_index = Configuration.node_data_popup;
1074             }
1075             else if ( key.equals( "color_according_to_species" ) ) {
1076                 key_index = Configuration.color_according_to_species;
1077             }
1078             else if ( key.equals( "show_node_names" ) ) {
1079                 key_index = Configuration.show_node_names;
1080             }
1081             else if ( key.equals( "show_taxonomy" ) || key.equals( "show_taxonomy_code" ) ) {
1082                 key_index = Configuration.show_tax_code;
1083                 if ( key.equals( "show_taxonomy" ) ) {
1084                     ForesterUtil
1085                             .printWarningMessage( Constants.PRG_NAME,
1086                                                   "configuration key [show_taxonomy] is deprecated, use [show_taxonomy_code] instead" );
1087                 }
1088             }
1089             else if ( key.equals( "write_br_length_values" ) ) {
1090                 ForesterUtil.printWarningMessage( Constants.PRG_NAME,
1091                                                   "configuration key [write_br_length_values] is deprecated" );
1092                 key_index = DEPRECATED;
1093             }
1094             else if ( key.equals( "write_bootstrap_values" ) || key.equals( "write_confidence_values" ) ) {
1095                 key_index = Configuration.write_confidence_values;
1096                 if ( key.equals( "write_bootstrap_values" ) ) {
1097                     ForesterUtil
1098                             .printWarningMessage( Constants.PRG_NAME,
1099                                                   "configuration key [write_bootstrap_values] is deprecated, use [write_confidence_values] instead" );
1100                 }
1101             }
1102             else if ( key.equals( "write_events" ) || key.equals( "write_dup_spec" ) ) {
1103                 key_index = Configuration.write_events;
1104                 if ( key.equals( "write_dup_spec" ) ) {
1105                     ForesterUtil
1106                             .printWarningMessage( Constants.PRG_NAME,
1107                                                   "configuration key [write_dup_spec] is deprecated, use [write_events] instead" );
1108                 }
1109             }
1110             else if ( key.equals( "color_branches" ) ) {
1111                 key_index = Configuration.color_branches;
1112             }
1113             else if ( key.equals( "width_branches" ) ) {
1114                 key_index = Configuration.width_branches;
1115             }
1116             else if ( key.equals( "color_orthologous" ) ) {
1117                 ForesterUtil.printWarningMessage( Constants.PRG_NAME,
1118                                                   "configuration key [color_orthologous] is deprecated" );
1119             }
1120             else if ( key.equals( "color_subtree_neighbors" ) ) {
1121                 ForesterUtil.printWarningMessage( Constants.PRG_NAME,
1122                                                   "configuration key [color_subtree_neighbors] is deprecated" );
1123             }
1124             else if ( key.equals( "color_super_orthologous" ) ) {
1125                 ForesterUtil.printWarningMessage( Constants.PRG_NAME,
1126                                                   "configuration key [color_super_orthologous] is deprecated" );
1127             }
1128             else if ( key.equals( "mark_nodes_with_box" ) ) {
1129                 ForesterUtil.printWarningMessage( Constants.PRG_NAME,
1130                                                   "configuration key [mark_nodes_with_box] is deprecated" );
1131                 key_index = DEPRECATED;
1132             }
1133             else if ( key.equals( "show_domain_architectures" ) ) {
1134                 key_index = Configuration.show_domain_architectures;
1135             }
1136             else if ( key.equals( "show_annotations" ) ) {
1137                 key_index = Configuration.show_annotation;
1138             }
1139             else if ( key.equals( "show_binary_characters" ) ) {
1140                 key_index = Configuration.show_binary_characters;
1141             }
1142             else if ( key.equals( "show_binary_character_counts" ) ) {
1143                 key_index = Configuration.show_binary_character_counts;
1144             }
1145             else if ( key.equals( "show_gene_names" ) ) {
1146                 key_index = Configuration.show_gene_names;
1147             }
1148             else if ( key.equals( "show_gene_symbols" ) ) {
1149                 key_index = Configuration.show_gene_symbols;
1150             }
1151             else if ( key.equals( "show_sequence_acc" ) ) {
1152                 key_index = Configuration.show_sequence_acc;
1153             }
1154             else if ( key.equals( "show_node_ids" ) ) {
1155                 ForesterUtil
1156                         .printWarningMessage( Constants.PRG_NAME, "configuration key [show_node_ids] is deprecated" );
1157                 key_index = DEPRECATED;
1158             }
1159             else if ( key.equals( "display_internal_data" ) ) {
1160                 key_index = Configuration.display_internal_data;
1161             }
1162             else if ( key.equals( "dynamically_hide_data" ) ) {
1163                 key_index = Configuration.dynamically_hide_data;
1164             }
1165             else if ( key.equals( "show_taxonomy_names" ) ) {
1166                 ForesterUtil.printWarningMessage( Constants.PRG_NAME,
1167                                                   "configuration key [show_taxonomy_names] is deprecated" );
1168                 key_index = DEPRECATED;
1169             }
1170             else if ( key.equals( "show_taxonomy_scientific_names" ) ) {
1171                 key_index = Configuration.show_taxonomy_scientific_names;
1172             }
1173             else if ( key.equals( "show_taxonomy_common_names" ) ) {
1174                 key_index = Configuration.show_taxonomy_common_names;
1175             }
1176             else if ( key.equals( "show_taxonomy_images" ) ) {
1177                 key_index = Configuration.show_taxonomy_images;
1178             }
1179             else if ( key.equals( "color_according_to_annotation" ) ) {
1180                 key_index = Configuration.color_according_to_annotation;
1181             }
1182             else if ( key.equals( "show_property" ) ) {
1183                 key_index = Configuration.show_property;
1184             }
1185             else if ( key.equals( "show_vector_data" ) ) {
1186                 key_index = Configuration.show_vector_data;
1187             }
1188             else if ( key.equals( "show_relation_confidence" ) ) {
1189                 key_index = Configuration.show_relation_confidence;
1190             }
1191             // If we've found the key, set the values
1192             if ( key_index >= 0 ) {
1193                 display_options[ key_index ][ 1 ] = ( String ) st.nextElement();
1194                 display_options[ key_index ][ 2 ] = ( String ) st.nextElement();
1195                 // otherwise, keep looking
1196             }
1197             else {
1198                 if ( key_index == DEPRECATED ) {
1199                     // Deprecated.
1200                 }
1201                 else if ( key.equals( "click_to" ) ) {
1202                     final String click_to_name = ( String ) st.nextElement();
1203                     key_index = getClickToIndex( click_to_name );
1204                     if ( key_index >= 0 ) {
1205                         clickto_options[ key_index ][ 1 ] = ( String ) st.nextElement();
1206                     }
1207                     else if ( key_index == DEPRECATED ) {
1208                         // Deprecated.
1209                     }
1210                     else {
1211                         ForesterUtil.printWarningMessage( Constants.PRG_NAME, "unknown click-to option: "
1212                                 + click_to_name );
1213                     }
1214                 }
1215                 else if ( key.equals( "species_color" ) ) {
1216                     getSpeciesColors().put( ( String ) st.nextElement(), Color.decode( ( String ) st.nextElement() ) );
1217                 }
1218                 else if ( key.equals( "domain_color" ) ) {
1219                     getDomainColors().put( ( String ) st.nextElement(), Color.decode( ( String ) st.nextElement() ) );
1220                 }
1221                 else if ( key.equals( "annotation_color" ) ) {
1222                     getAnnotationColors()
1223                             .put( ( String ) st.nextElement(), Color.decode( ( String ) st.nextElement() ) );
1224                 }
1225                 else if ( key.equals( "function_color" ) ) {
1226                     ForesterUtil.printWarningMessage( Constants.PRG_NAME,
1227                                                       "configuration key [function_color] is deprecated" );
1228                 }
1229                 else if ( key.equals( DISPLAY_COLOR_KEY ) ) {
1230                     getDisplayColors().put( ( String ) st.nextElement(), Color.decode( ( String ) st.nextElement() ) );
1231                 }
1232                 else if ( key.equals( WEB_LINK_KEY ) ) {
1233                     if ( st.countTokens() == 3 ) {
1234                         createWebLink( ( String ) st.nextElement(),
1235                                        ( String ) st.nextElement(),
1236                                        ( String ) st.nextElement() );
1237                     }
1238                     else {
1239                         ForesterUtil.printWarningMessage( Constants.PRG_NAME,
1240                                                           "illegal format in configuration file for key [" + key + "]" );
1241                     }
1242                 }
1243                 else {
1244                     ForesterUtil.printWarningMessage( Constants.PRG_NAME, "unknown configuration key [" + key
1245                             + "] in: " + config_filename );
1246                 }
1247             }
1248         }
1249         else {
1250             ForesterUtil.printWarningMessage( Constants.PRG_NAME, "unknown configuration key [" + key + "] in: "
1251                     + config_filename );
1252         }
1253     }
1254
1255     private void setMinConfidenceValue( final double min_confidence_value ) {
1256         _min_confidence_value = min_confidence_value;
1257     }
1258
1259     void setNodeLabelDirection( final NODE_LABEL_DIRECTION node_label_direction ) {
1260         _node_label_direction = node_label_direction;
1261     }
1262
1263     private void setNumberOfDigitsAfterCommaForBranchLengthValue( final short _number_of_digits_after_comma_for_branch_length_values ) {
1264         this._number_of_digits_after_comma_for_branch_length_values = _number_of_digits_after_comma_for_branch_length_values;
1265     }
1266
1267     private void setNumberOfDigitsAfterCommaForConfidenceValues( final short _number_of_digits_after_comma_for_confidence_values ) {
1268         this._number_of_digits_after_comma_for_confidence_values = _number_of_digits_after_comma_for_confidence_values;
1269     }
1270
1271     private void setOvMaxHeight( final short ov_max_height ) {
1272         _ov_max_height = ov_max_height;
1273     }
1274
1275     private void setOvMaxWidth( final short ov_max_width ) {
1276         _ov_max_width = ov_max_width;
1277     }
1278
1279     private void setOvPlacement( final OVERVIEW_PLACEMENT_TYPE ov_placement ) {
1280         _ov_placement = ov_placement;
1281     }
1282
1283     void setPhylogenyGraphicsType( final PHYLOGENY_GRAPHICS_TYPE phylogeny_graphics_type ) {
1284         _phylogeny_graphics_type = phylogeny_graphics_type;
1285     }
1286
1287     private void setPrintLineWidth( final float print_line_width ) {
1288         _print_line_width = print_line_width;
1289     }
1290
1291     private void setReplaceUnderscoresInNhParsing( final boolean nh_parsing_replace_underscores ) {
1292         _nh_parsing_replace_underscores = nh_parsing_replace_underscores;
1293     }
1294
1295     private void setShowBranchLengthValues( final boolean show_branch_length_values ) {
1296         _show_branch_length_values = show_branch_length_values;
1297     }
1298
1299     private void setShowOverview( final boolean show_overview ) {
1300         _show_overview = show_overview;
1301     }
1302
1303     private void setShowScale( final boolean show_scale ) {
1304         _show_scale = show_scale;
1305     }
1306
1307     private void setValidatePhyloXmlAgainstSchema( final boolean validate_against_phyloxml_xsd_schema ) {
1308         _validate_against_phyloxml_xsd_schema = validate_against_phyloxml_xsd_schema;
1309     }
1310
1311     void setWebLinks( final SortedMap<String, WebLink> weblinks ) {
1312         _weblinks = weblinks;
1313     }
1314
1315     static String getDefaultFontFamilyName() {
1316         return DEFAULT_FONT_FAMILY;
1317     }
1318
1319     static enum TRIPLET {
1320         TRUE, FALSE, UNKNOWN
1321     }
1322
1323     public Color getDomainStructureFontColor() {
1324         return _domain_structure_font_color;
1325     }
1326
1327     public Color getDomainStructureBaseColor() {
1328         return _domain_structure_base_color;
1329     }
1330
1331     public boolean isColorLabelsSameAsParentBranch() {
1332         return _color_labels_same_as_parent_branch;
1333     }
1334
1335     public boolean isShowDomainLabels() {
1336         return _show_domain_labels;
1337     }
1338
1339     public boolean isAbbreviateScientificTaxonNames() {
1340         return _abbreviate_scientific_names;
1341     }
1342 }