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