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