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