34a225e4e36609828d1999cf0248ee95edf06f79
[jalview.git] / forester / java / src / org / forester / archaeopteryx / Options.java
1 // $Id:
2 // FORESTER -- software libraries and applications
3 // for evolutionary biology research and applications.
4 //
5 // Copyright (C) 2009 Christian M. Zmasek
6 // Copyright (C) 2009 Burnham Institute for Medical Research
7 // All rights reserved
8 //
9 // This library is free software; you can redistribute it and/or
10 // modify it under the terms of the GNU Lesser General Public
11 // License as published by the Free Software Foundation; either
12 // version 2.1 of the License, or (at your option) any later version.
13 //
14 // This library is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 // Lesser General Public License for more details.
18 //
19 // You should have received a copy of the GNU Lesser General Public
20 // License along with this library; if not, write to the Free Software
21 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 //
23 // Contact: phylosoft @ gmail . com
24 // WWW: https://sites.google.com/site/cmzmasek/home/software/forester
25
26 package org.forester.archaeopteryx;
27
28 import java.awt.Font;
29
30 import org.forester.io.parsers.nhx.NHXParser.TAXONOMY_EXTRACTION;
31 import org.forester.phylogeny.PhylogenyNode.NH_CONVERSION_SUPPORT_VALUE_STYLE;
32 import org.forester.phylogeny.data.NodeData;
33 import org.forester.phylogeny.data.NodeData.NODE_DATA;
34 import org.forester.phylogeny.data.NodeVisualization;
35 import org.forester.phylogeny.data.NodeVisualization.NodeFill;
36 import org.forester.phylogeny.data.NodeVisualization.NodeShape;
37 import org.forester.util.ForesterUtil;
38
39 /*
40  * This is to hold changeable options.
41  */
42 final public class Options {
43
44     static final double                       MIN_CONFIDENCE_DEFAULT = 0.0;
45     private boolean                           _color_by_taxonomic_group;
46     private boolean                           _show_branch_length_values;
47     private boolean                           _internal_number_are_confidence_for_nh_parsing;
48     private boolean                           _show_scale;
49     private boolean                           _show_overview;
50     private boolean                           _antialias_screen;
51     private boolean                           _antialias_print;
52     private boolean                           _graphics_export_visible_only;
53     private int                               _print_size_x;
54     private int                               _print_size_y;
55     private double                            _min_confidence_value;
56     private boolean                           _print_black_and_white;
57     private boolean                           _print_using_actual_size;
58     private boolean                           _graphics_export_using_actual_size;
59     private PHYLOGENY_GRAPHICS_TYPE           _phylogeny_graphics_type;
60     private CLADOGRAM_TYPE                    _cladogram_type;
61     private OVERVIEW_PLACEMENT_TYPE           _ov_placement;
62     private NODE_LABEL_DIRECTION              _node_label_direction;
63     private Font                              _base_font;
64     private boolean                           _match_whole_terms_only;
65     private boolean                           _search_case_sensitive;
66     private float                             _print_line_width;
67     private boolean                           _inverse_search_result;
68     private double                            _scale_bar_length;
69     private short                             _number_of_digits_after_comma_for_confidence_values;
70     private short                             _number_of_digits_after_comma_for_branch_length_values;
71     private boolean                           _nh_parsing_replace_underscores;
72     private TAXONOMY_EXTRACTION               _taxonomy_extraction;
73     private boolean                           _editable;
74     private boolean                           _background_color_gradient;
75     private boolean                           _show_domain_labels;
76     private boolean                           _show_annotation_ref_source;
77     private boolean                           _color_labels_same_as_parent_branch;
78     private boolean                           _abbreviate_scientific_names;
79     private NodeVisualization.NodeShape       _default_node_shape;
80     private NodeVisualization.NodeFill        _default_node_fill;
81     private short                             _default_node_shape_size;
82     private boolean                           _taxonomy_colorize_node_shapes;
83     private boolean                           _show_default_node_shapes_internal;
84     private boolean                           _show_default_node_shapes_external;
85     private boolean                           _show_confidence_stddev;
86     private NH_CONVERSION_SUPPORT_VALUE_STYLE _nh_conversion_support_value_style;
87     private NODE_DATA                         _ext_desc_data_to_return;
88
89     private Options() {
90         init();
91     }
92
93     public NodeData.NODE_DATA getExtDescNodeDataToReturn() {
94         return _ext_desc_data_to_return;
95     }
96
97     public final boolean isShowDomainLabels() {
98         return _show_domain_labels;
99     }
100
101     public final boolean isShowAnnotationRefSource() {
102         return _show_annotation_ref_source;
103     }
104
105     public final void setShowAnnotationRefSource( final boolean show_annotation_ref_source ) {
106         _show_annotation_ref_source = show_annotation_ref_source;
107     }
108
109     public void setBackgroundColorGradient( final boolean background_color_gradient ) {
110         _background_color_gradient = background_color_gradient;
111     }
112
113     public void setColorLabelsSameAsParentBranch( final boolean color_labels_same_as_parent_branch ) {
114         _color_labels_same_as_parent_branch = color_labels_same_as_parent_branch;
115     }
116
117     public void setExtDescNodeDataToReturn( final NODE_DATA ext_desc_data_to_return ) {
118         _ext_desc_data_to_return = ext_desc_data_to_return;
119     }
120
121     public void setShowDomainLabels( final boolean show_domain_labels ) {
122         _show_domain_labels = show_domain_labels;
123     }
124
125     final Font getBaseFont() {
126         return _base_font;
127     }
128
129     final CLADOGRAM_TYPE getCladogramType() {
130         return _cladogram_type;
131     }
132
133     final NodeFill getDefaultNodeFill() {
134         return _default_node_fill;
135     }
136
137     final NodeShape getDefaultNodeShape() {
138         return _default_node_shape;
139     }
140
141     final short getDefaultNodeShapeSize() {
142         return _default_node_shape_size;
143     }
144
145     final double getMinConfidenceValue() {
146         return _min_confidence_value;
147     }
148
149     NH_CONVERSION_SUPPORT_VALUE_STYLE getNhConversionSupportValueStyle() {
150         return _nh_conversion_support_value_style;
151     }
152
153     final NODE_LABEL_DIRECTION getNodeLabelDirection() {
154         return _node_label_direction;
155     }
156
157     final short getNumberOfDigitsAfterCommaForBranchLengthValues() {
158         return _number_of_digits_after_comma_for_branch_length_values;
159     }
160
161     final short getNumberOfDigitsAfterCommaForConfidenceValues() {
162         return _number_of_digits_after_comma_for_confidence_values;
163     }
164
165     final OVERVIEW_PLACEMENT_TYPE getOvPlacement() {
166         return _ov_placement;
167     }
168
169     final PHYLOGENY_GRAPHICS_TYPE getPhylogenyGraphicsType() {
170         return _phylogeny_graphics_type;
171     }
172
173     final float getPrintLineWidth() {
174         return _print_line_width;
175     }
176
177     final int getPrintSizeX() {
178         return _print_size_x;
179     }
180
181     final int getPrintSizeY() {
182         return _print_size_y;
183     }
184
185     final double getScaleBarLength() {
186         return _scale_bar_length;
187     }
188
189     final TAXONOMY_EXTRACTION getTaxonomyExtraction() {
190         return _taxonomy_extraction;
191     }
192
193     final boolean isAbbreviateScientificTaxonNames() {
194         return _abbreviate_scientific_names;
195     }
196
197     boolean isAllowMagnificationOfTaxonomyImages() {
198         return true;
199     }
200
201     final boolean isAntialiasPrint() {
202         return _antialias_print;
203     }
204
205     final boolean isAntialiasScreen() {
206         return _antialias_screen;
207     }
208
209     final boolean isBackgroundColorGradient() {
210         return _background_color_gradient;
211     }
212
213     final boolean isColorLabelsSameAsParentBranch() {
214         return _color_labels_same_as_parent_branch;
215     }
216
217     final boolean isEditable() {
218         return _editable;
219     }
220
221     final boolean isGraphicsExportUsingActualSize() {
222         return _graphics_export_using_actual_size;
223     }
224
225     final boolean isGraphicsExportVisibleOnly() {
226         return _graphics_export_visible_only;
227     }
228
229     final boolean isInternalNumberAreConfidenceForNhParsing() {
230         return _internal_number_are_confidence_for_nh_parsing;
231     }
232
233     final boolean isInverseSearchResult() {
234         return _inverse_search_result;
235     }
236
237     final boolean isMatchWholeTermsOnly() {
238         return _match_whole_terms_only;
239     }
240
241     final boolean isPrintBlackAndWhite() {
242         return _print_black_and_white;
243     }
244
245     final boolean isPrintUsingActualSize() {
246         return _print_using_actual_size;
247     }
248
249     final boolean isReplaceUnderscoresInNhParsing() {
250         return _nh_parsing_replace_underscores;
251     }
252
253     final boolean isSearchCaseSensitive() {
254         return _search_case_sensitive;
255     }
256
257     final boolean isShowBranchLengthValues() {
258         return _show_branch_length_values;
259     }
260
261     final boolean isColorByTaxonomicGroup() {
262         return _color_by_taxonomic_group;
263     }
264     
265     
266     boolean isShowConfidenceStddev() {
267         return _show_confidence_stddev;
268     }
269
270     boolean isShowDefaultNodeShapesExternal() {
271         return _show_default_node_shapes_external;
272     }
273
274     boolean isShowDefaultNodeShapesInternal() {
275         return _show_default_node_shapes_internal;
276     }
277
278     final boolean isShowOverview() {
279         return _show_overview;
280     }
281
282     final boolean isShowScale() {
283         return _show_scale;
284     }
285
286     boolean isTaxonomyColorizeNodeShapes() {
287         return _taxonomy_colorize_node_shapes;
288     }
289
290     final void setAbbreviateScientificTaxonNames( final boolean abbreviate_scientific_names ) {
291         _abbreviate_scientific_names = abbreviate_scientific_names;
292     }
293
294     final void setAntialiasPrint( final boolean antialias_print ) {
295         _antialias_print = antialias_print;
296     }
297
298     final void setAntialiasScreen( final boolean antialias_screen ) {
299         _antialias_screen = antialias_screen;
300     }
301
302     final void setBaseFont( final Font base_font ) {
303         _base_font = base_font;
304     }
305
306     final void setCladogramType( final CLADOGRAM_TYPE cladogram_type ) {
307         _cladogram_type = cladogram_type;
308     }
309
310     final void setDefaultNodeFill( final NodeFill default_node_fill ) {
311         _default_node_fill = default_node_fill;
312     }
313
314     final void setDefaultNodeShape( final NodeShape default_node_shape ) {
315         _default_node_shape = default_node_shape;
316     }
317
318     final void setDefaultNodeShapeSize( final short default_node_shape_size ) {
319         _default_node_shape_size = default_node_shape_size;
320     }
321
322     final void setEditable( final boolean editable ) {
323         _editable = editable;
324     }
325
326     final void setGraphicsExportUsingActualSize( final boolean graphics_export_using_actual_size ) {
327         _graphics_export_using_actual_size = graphics_export_using_actual_size;
328         if ( !graphics_export_using_actual_size ) {
329             setGraphicsExportVisibleOnly( false );
330         }
331     }
332
333     final void setGraphicsExportVisibleOnly( final boolean graphics_export_visible_only ) {
334         _graphics_export_visible_only = graphics_export_visible_only;
335         if ( graphics_export_visible_only ) {
336             setGraphicsExportUsingActualSize( true );
337         }
338     }
339
340     final void setInternalNumberAreConfidenceForNhParsing( final boolean internal_number_are_confidence_for_nh_parsing ) {
341         _internal_number_are_confidence_for_nh_parsing = internal_number_are_confidence_for_nh_parsing;
342     }
343
344     final void setInverseSearchResult( final boolean inverse_search_result ) {
345         _inverse_search_result = inverse_search_result;
346     }
347
348     final void setMatchWholeTermsOnly( final boolean search_whole_words_only ) {
349         _match_whole_terms_only = search_whole_words_only;
350     }
351
352     final void setMinConfidenceValue( final double min_confidence_value ) {
353         _min_confidence_value = min_confidence_value;
354     }
355
356     void setNhConversionSupportValueStyle( final NH_CONVERSION_SUPPORT_VALUE_STYLE nh_conversion_support_value_style ) {
357         _nh_conversion_support_value_style = nh_conversion_support_value_style;
358     }
359
360     final void setNodeLabelDirection( final NODE_LABEL_DIRECTION node_label_direction ) {
361         _node_label_direction = node_label_direction;
362     }
363
364     final void setOvPlacement( final OVERVIEW_PLACEMENT_TYPE ov_placement ) {
365         _ov_placement = ov_placement;
366     }
367
368     final void setPhylogenyGraphicsType( final PHYLOGENY_GRAPHICS_TYPE phylogeny_graphics_type ) {
369         _phylogeny_graphics_type = phylogeny_graphics_type;
370     }
371
372     final void setPrintBlackAndWhite( final boolean print_black_and_white ) {
373         _print_black_and_white = print_black_and_white;
374     }
375
376     final void setPrintLineWidth( final float print_line_width ) {
377         _print_line_width = print_line_width;
378     }
379
380     final void setPrintSizeX( final int print_size_x ) {
381         _print_size_x = print_size_x;
382     }
383
384     final void setPrintSizeY( final int print_size_y ) {
385         _print_size_y = print_size_y;
386     }
387
388     final void setPrintUsingActualSize( final boolean print_using_actual_size ) {
389         _print_using_actual_size = print_using_actual_size;
390     }
391
392     final void setReplaceUnderscoresInNhParsing( final boolean nh_parsing_replace_underscores ) {
393         _nh_parsing_replace_underscores = nh_parsing_replace_underscores;
394     }
395
396     final void setScaleBarLength( final double scale_bar_length ) {
397         _scale_bar_length = scale_bar_length;
398     }
399
400     final void setSearchCaseSensitive( final boolean search_case_sensitive ) {
401         _search_case_sensitive = search_case_sensitive;
402     }
403
404     final void setShowBranchLengthValues( final boolean show_branch_length_values ) {
405         _show_branch_length_values = show_branch_length_values;
406     }
407
408     final void setColorByTaxonomicGroup( final boolean color_by_taxonomic_group ) {
409         _color_by_taxonomic_group = color_by_taxonomic_group;
410     }
411     
412     void setShowConfidenceStddev( final boolean show_confidence_stddev ) {
413         _show_confidence_stddev = show_confidence_stddev;
414     }
415
416     void setShowDefaultNodeShapesExternal( final boolean show_default_node_shapes_external ) {
417         _show_default_node_shapes_external = show_default_node_shapes_external;
418     }
419
420     void setShowDefaultNodeShapesInternal( final boolean show_default_node_shapes_internal ) {
421         _show_default_node_shapes_internal = show_default_node_shapes_internal;
422     }
423
424     final void setShowOverview( final boolean show_overview ) {
425         _show_overview = show_overview;
426     }
427
428     final void setShowScale( final boolean show_scale ) {
429         _show_scale = show_scale;
430     }
431
432     void setTaxonomyColorizeNodeShapes( final boolean taxonomy_colorize_node_shapes ) {
433         _taxonomy_colorize_node_shapes = taxonomy_colorize_node_shapes;
434     }
435
436     final void setTaxonomyExtraction( final TAXONOMY_EXTRACTION taxonomy_extraction ) {
437         _taxonomy_extraction = taxonomy_extraction;
438     }
439
440     final private void init() {
441         _default_node_shape = NodeShape.CIRCLE;
442         _default_node_fill = NodeFill.GRADIENT;
443         _default_node_shape_size = Constants.DEFAULT_NODE_SHAPE_SIZE_DEFAULT;
444         _taxonomy_colorize_node_shapes = false;
445         _show_branch_length_values = false;
446         _internal_number_are_confidence_for_nh_parsing = false;
447         _show_scale = false;
448         _antialias_screen = false;
449         _antialias_print = true;
450         _graphics_export_visible_only = false;
451         _editable = true;
452         _background_color_gradient = false;
453         _show_default_node_shapes_internal = false;
454         _show_default_node_shapes_external = false;
455         if ( AptxUtil.isUsOrCanada() ) {
456             _print_size_x = Constants.US_LETTER_SIZE_X;
457             _print_size_y = Constants.US_LETTER_SIZE_Y;
458         }
459         else {
460             _print_size_x = Constants.A4_SIZE_X;
461             _print_size_y = Constants.A4_SIZE_Y;
462         }
463         _min_confidence_value = MIN_CONFIDENCE_DEFAULT;
464         _print_black_and_white = false;
465         _print_using_actual_size = false;
466         _graphics_export_using_actual_size = true;
467         _phylogeny_graphics_type = PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR;
468         _base_font = new Font( Configuration.getDefaultFontFamilyName(), Font.PLAIN, 10 );
469         _match_whole_terms_only = false;
470         _search_case_sensitive = false;
471         _print_line_width = Constants.PDF_LINE_WIDTH_DEFAULT;
472         _show_overview = true;
473         _ov_placement = OVERVIEW_PLACEMENT_TYPE.UPPER_LEFT;
474         _node_label_direction = NODE_LABEL_DIRECTION.HORIZONTAL;
475         _inverse_search_result = false;
476         _scale_bar_length = 0.0;
477         _number_of_digits_after_comma_for_branch_length_values = Constants.NUMBER_OF_DIGITS_AFTER_COMMA_FOR_BRANCH_LENGTH_VALUES_DEFAULT;
478         _number_of_digits_after_comma_for_confidence_values = Constants.NUMBER_OF_DIGITS_AFTER_COMMA_FOR_CONFIDENCE_VALUES_DEFAULT;
479         _nh_parsing_replace_underscores = false;
480         _taxonomy_extraction = TAXONOMY_EXTRACTION.NO;
481         _cladogram_type = Constants.CLADOGRAM_TYPE_DEFAULT;
482         _show_domain_labels = true;
483         _show_annotation_ref_source = true;
484         setAbbreviateScientificTaxonNames( false );
485         _color_labels_same_as_parent_branch = false;
486         _show_confidence_stddev = true;
487         _nh_conversion_support_value_style = NH_CONVERSION_SUPPORT_VALUE_STYLE.NONE;
488         _ext_desc_data_to_return = NODE_DATA.UNKNOWN;
489     }
490
491     final private void setNumberOfDigitsAfterCommaForBranchLength( final short number_of_digits_after_comma_for_branch_length_values ) {
492         _number_of_digits_after_comma_for_branch_length_values = number_of_digits_after_comma_for_branch_length_values;
493     }
494
495     final private void setNumberOfDigitsAfterCommaForConfidenceValues( final short number_of_digits_after_comma_for_confidence_values ) {
496         _number_of_digits_after_comma_for_confidence_values = number_of_digits_after_comma_for_confidence_values;
497     }
498
499     public final static Options createInstance( final Configuration configuration ) {
500         final Options instance = createDefaultInstance();
501         if ( configuration != null ) {
502             instance.setAntialiasScreen( configuration.isAntialiasScreen() );
503             instance.setShowScale( configuration.isShowScale() );
504             instance.setShowBranchLengthValues( configuration.isShowBranchLengthValues() );
505             instance.setShowOverview( configuration.isShowOverview() );
506             instance.setColorByTaxonomicGroup( configuration.isColorByTaxonomicGroup() );
507             instance.setCladogramType( configuration.getCladogramType() );
508             instance.setOvPlacement( configuration.getOvPlacement() );
509             instance.setPrintLineWidth( configuration.getPrintLineWidth() );
510             instance.setNodeLabelDirection( configuration.getNodeLabelDirection() );
511             instance.setBackgroundColorGradient( configuration.isBackgroundColorGradient() );
512             if ( configuration.getNumberOfDigitsAfterCommaForBranchLengthValues() >= 0 ) {
513                 instance.setNumberOfDigitsAfterCommaForBranchLength( configuration
514                         .getNumberOfDigitsAfterCommaForBranchLengthValues() );
515             }
516             if ( configuration.getNumberOfDigitsAfterCommaForConfidenceValues() >= 0 ) {
517                 instance.setNumberOfDigitsAfterCommaForConfidenceValues( configuration
518                         .getNumberOfDigitsAfterCommaForConfidenceValues() );
519             }
520             instance.setTaxonomyExtraction( configuration.getTaxonomyExtraction() );
521             instance.setReplaceUnderscoresInNhParsing( configuration.isReplaceUnderscoresInNhParsing() );
522             instance.setInternalNumberAreConfidenceForNhParsing( configuration
523                     .isInternalNumberAreConfidenceForNhParsing() );
524             instance.setEditable( configuration.isEditable() );
525             instance.setColorLabelsSameAsParentBranch( configuration.isColorLabelsSameAsParentBranch() );
526             instance.setShowDomainLabels( configuration.isShowDomainLabels() );
527             instance.setShowAnnotationRefSource( configuration.isShowAnnotationRefSource() );
528             instance.setAbbreviateScientificTaxonNames( configuration.isAbbreviateScientificTaxonNames() );
529             if ( configuration.getMinConfidenceValue() != MIN_CONFIDENCE_DEFAULT ) {
530                 instance.setMinConfidenceValue( configuration.getMinConfidenceValue() );
531             }
532             if ( configuration.getGraphicsExportX() > 0 ) {
533                 instance.setPrintSizeX( configuration.getGraphicsExportX() );
534             }
535             if ( configuration.getGraphicsExportY() > 0 ) {
536                 instance.setPrintSizeY( configuration.getGraphicsExportY() );
537             }
538             if ( configuration.getBaseFontSize() > 0 ) {
539                 instance.setBaseFont( instance.getBaseFont().deriveFont( ( float ) configuration.getBaseFontSize() ) );
540             }
541             if ( !ForesterUtil.isEmpty( configuration.getBaseFontFamilyName() ) ) {
542                 instance.setBaseFont( new Font( configuration.getBaseFontFamilyName(), Font.PLAIN, instance
543                         .getBaseFont().getSize() ) );
544             }
545             if ( configuration.getPhylogenyGraphicsType() != null ) {
546                 instance.setPhylogenyGraphicsType( configuration.getPhylogenyGraphicsType() );
547             }
548             if ( configuration.getDefaultNodeFill() != null ) {
549                 instance.setDefaultNodeFill( configuration.getDefaultNodeFill() );
550             }
551             if ( configuration.getDefaultNodeShape() != null ) {
552                 instance.setDefaultNodeShape( configuration.getDefaultNodeShape() );
553             }
554             if ( configuration.getDefaultNodeShapeSize() >= 0 ) {
555                 instance.setDefaultNodeShapeSize( configuration.getDefaultNodeShapeSize() );
556             }
557             instance.setTaxonomyColorizeNodeShapes( configuration.isTaxonomyColorizeNodeShapes() );
558             instance.setShowDefaultNodeShapesInternal( configuration.isShowDefaultNodeShapesInternal() );
559             instance.setShowDefaultNodeShapesExternal( configuration.isShowDefaultNodeShapesExternal() );
560             if ( configuration.getExtDescNodeDataToReturn() != null ) {
561                 instance.setExtDescNodeDataToReturn( configuration.getExtDescNodeDataToReturn() );
562             }
563         }
564         return instance;
565     }
566
567     final static Options createDefaultInstance() {
568         return new Options();
569     }
570
571     public static enum CLADOGRAM_TYPE {
572         NON_LINED_UP, EXT_NODE_SUM_DEP, TOTAL_NODE_SUM_DEP;
573     }
574
575     public static enum NODE_LABEL_DIRECTION {
576         HORIZONTAL, RADIAL;
577     }
578
579     public static enum PHYLOGENY_GRAPHICS_TYPE {
580         RECTANGULAR, TRIANGULAR, EURO_STYLE, ROUNDED, CONVEX, CURVED, UNROOTED, CIRCULAR;
581     }
582
583     static enum OVERVIEW_PLACEMENT_TYPE {
584         UPPER_LEFT( "upper left" ),
585         UPPER_RIGHT( "upper right" ),
586         LOWER_LEFT( "lower left" ),
587         LOWER_RIGHT( "lower right" );
588
589         private final String _name;
590
591         private OVERVIEW_PLACEMENT_TYPE( final String name ) {
592             _name = name;
593         }
594
595         @Override
596         public String toString() {
597             return _name;
598         }
599
600         public String toTag() {
601             return toString().replaceAll( " ", "_" );
602         }
603     }
604
605     public boolean isAllowFontSizeChange() {
606         return true;
607     }
608 }