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