cleanup
[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     boolean isShowConfidenceStddev() {
266         return _show_confidence_stddev;
267     }
268
269     boolean isShowDefaultNodeShapesExternal() {
270         return _show_default_node_shapes_external;
271     }
272
273     boolean isShowDefaultNodeShapesInternal() {
274         return _show_default_node_shapes_internal;
275     }
276
277     final boolean isShowOverview() {
278         return _show_overview;
279     }
280
281     final boolean isShowScale() {
282         return _show_scale;
283     }
284
285     boolean isTaxonomyColorizeNodeShapes() {
286         return _taxonomy_colorize_node_shapes;
287     }
288
289     final void setAbbreviateScientificTaxonNames( final boolean abbreviate_scientific_names ) {
290         _abbreviate_scientific_names = abbreviate_scientific_names;
291     }
292
293     final void setAntialiasPrint( final boolean antialias_print ) {
294         _antialias_print = antialias_print;
295     }
296
297     final void setAntialiasScreen( final boolean antialias_screen ) {
298         _antialias_screen = antialias_screen;
299     }
300
301     final void setBaseFont( final Font base_font ) {
302         _base_font = base_font;
303     }
304
305     final void setCladogramType( final CLADOGRAM_TYPE cladogram_type ) {
306         _cladogram_type = cladogram_type;
307     }
308
309     final void setDefaultNodeFill( final NodeFill default_node_fill ) {
310         _default_node_fill = default_node_fill;
311     }
312
313     final void setDefaultNodeShape( final NodeShape default_node_shape ) {
314         _default_node_shape = default_node_shape;
315     }
316
317     final void setDefaultNodeShapeSize( final short default_node_shape_size ) {
318         _default_node_shape_size = default_node_shape_size;
319     }
320
321     final void setEditable( final boolean editable ) {
322         _editable = editable;
323     }
324
325     final void setGraphicsExportUsingActualSize( final boolean graphics_export_using_actual_size ) {
326         _graphics_export_using_actual_size = graphics_export_using_actual_size;
327         if ( !graphics_export_using_actual_size ) {
328             setGraphicsExportVisibleOnly( false );
329         }
330     }
331
332     final void setGraphicsExportVisibleOnly( final boolean graphics_export_visible_only ) {
333         _graphics_export_visible_only = graphics_export_visible_only;
334         if ( graphics_export_visible_only ) {
335             setGraphicsExportUsingActualSize( true );
336         }
337     }
338
339     final void setInternalNumberAreConfidenceForNhParsing( final boolean internal_number_are_confidence_for_nh_parsing ) {
340         _internal_number_are_confidence_for_nh_parsing = internal_number_are_confidence_for_nh_parsing;
341     }
342
343     final void setInverseSearchResult( final boolean inverse_search_result ) {
344         _inverse_search_result = inverse_search_result;
345     }
346
347     final void setMatchWholeTermsOnly( final boolean search_whole_words_only ) {
348         _match_whole_terms_only = search_whole_words_only;
349     }
350
351     final void setMinConfidenceValue( final double min_confidence_value ) {
352         _min_confidence_value = min_confidence_value;
353     }
354
355     void setNhConversionSupportValueStyle( final NH_CONVERSION_SUPPORT_VALUE_STYLE nh_conversion_support_value_style ) {
356         _nh_conversion_support_value_style = nh_conversion_support_value_style;
357     }
358
359     final void setNodeLabelDirection( final NODE_LABEL_DIRECTION node_label_direction ) {
360         _node_label_direction = node_label_direction;
361     }
362
363     final void setOvPlacement( final OVERVIEW_PLACEMENT_TYPE ov_placement ) {
364         _ov_placement = ov_placement;
365     }
366
367     final void setPhylogenyGraphicsType( final PHYLOGENY_GRAPHICS_TYPE phylogeny_graphics_type ) {
368         _phylogeny_graphics_type = phylogeny_graphics_type;
369     }
370
371     final void setPrintBlackAndWhite( final boolean print_black_and_white ) {
372         _print_black_and_white = print_black_and_white;
373     }
374
375     final void setPrintLineWidth( final float print_line_width ) {
376         _print_line_width = print_line_width;
377     }
378
379     final void setPrintSizeX( final int print_size_x ) {
380         _print_size_x = print_size_x;
381     }
382
383     final void setPrintSizeY( final int print_size_y ) {
384         _print_size_y = print_size_y;
385     }
386
387     final void setPrintUsingActualSize( final boolean print_using_actual_size ) {
388         _print_using_actual_size = print_using_actual_size;
389     }
390
391     final void setReplaceUnderscoresInNhParsing( final boolean nh_parsing_replace_underscores ) {
392         _nh_parsing_replace_underscores = nh_parsing_replace_underscores;
393     }
394
395     final void setScaleBarLength( final double scale_bar_length ) {
396         _scale_bar_length = scale_bar_length;
397     }
398
399     final void setSearchCaseSensitive( final boolean search_case_sensitive ) {
400         _search_case_sensitive = search_case_sensitive;
401     }
402
403     final void setShowBranchLengthValues( final boolean show_branch_length_values ) {
404         _show_branch_length_values = show_branch_length_values;
405     }
406
407     final void setColorByTaxonomicGroup( final boolean color_by_taxonomic_group ) {
408         _color_by_taxonomic_group = color_by_taxonomic_group;
409     }
410
411     void setShowConfidenceStddev( final boolean show_confidence_stddev ) {
412         _show_confidence_stddev = show_confidence_stddev;
413     }
414
415     void setShowDefaultNodeShapesExternal( final boolean show_default_node_shapes_external ) {
416         _show_default_node_shapes_external = show_default_node_shapes_external;
417     }
418
419     void setShowDefaultNodeShapesInternal( final boolean show_default_node_shapes_internal ) {
420         _show_default_node_shapes_internal = show_default_node_shapes_internal;
421     }
422
423     final void setShowOverview( final boolean show_overview ) {
424         _show_overview = show_overview;
425     }
426
427     final void setShowScale( final boolean show_scale ) {
428         _show_scale = show_scale;
429     }
430
431     void setTaxonomyColorizeNodeShapes( final boolean taxonomy_colorize_node_shapes ) {
432         _taxonomy_colorize_node_shapes = taxonomy_colorize_node_shapes;
433     }
434
435     final void setTaxonomyExtraction( final TAXONOMY_EXTRACTION taxonomy_extraction ) {
436         _taxonomy_extraction = taxonomy_extraction;
437     }
438
439     final private void init() {
440         _default_node_shape = NodeShape.CIRCLE;
441         _default_node_fill = NodeFill.GRADIENT;
442         _default_node_shape_size = Constants.DEFAULT_NODE_SHAPE_SIZE_DEFAULT;
443         _taxonomy_colorize_node_shapes = false;
444         _show_branch_length_values = false;
445         _internal_number_are_confidence_for_nh_parsing = false;
446         _show_scale = false;
447         _antialias_screen = true;
448         _antialias_print = true;
449         _graphics_export_visible_only = false;
450         _editable = true;
451         _background_color_gradient = false;
452         _show_default_node_shapes_internal = false;
453         _show_default_node_shapes_external = false;
454         if ( AptxUtil.isUsOrCanada() ) {
455             _print_size_x = Constants.US_LETTER_SIZE_X;
456             _print_size_y = Constants.US_LETTER_SIZE_Y;
457         }
458         else {
459             _print_size_x = Constants.A4_SIZE_X;
460             _print_size_y = Constants.A4_SIZE_Y;
461         }
462         _min_confidence_value = MIN_CONFIDENCE_DEFAULT;
463         _print_black_and_white = false;
464         _print_using_actual_size = false;
465         _graphics_export_using_actual_size = true;
466         _phylogeny_graphics_type = PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR;
467         _base_font = new Font( Configuration.getDefaultFontFamilyName(), Font.PLAIN, 10 );
468         _match_whole_terms_only = false;
469         _search_case_sensitive = false;
470         _print_line_width = Constants.PDF_LINE_WIDTH_DEFAULT;
471         _show_overview = true;
472         _ov_placement = OVERVIEW_PLACEMENT_TYPE.UPPER_LEFT;
473         _node_label_direction = NODE_LABEL_DIRECTION.HORIZONTAL;
474         _inverse_search_result = false;
475         _scale_bar_length = 0.0;
476         _number_of_digits_after_comma_for_branch_length_values = Constants.NUMBER_OF_DIGITS_AFTER_COMMA_FOR_BRANCH_LENGTH_VALUES_DEFAULT;
477         _number_of_digits_after_comma_for_confidence_values = Constants.NUMBER_OF_DIGITS_AFTER_COMMA_FOR_CONFIDENCE_VALUES_DEFAULT;
478         _nh_parsing_replace_underscores = false;
479         _taxonomy_extraction = TAXONOMY_EXTRACTION.NO;
480         _cladogram_type = Constants.CLADOGRAM_TYPE_DEFAULT;
481         _show_domain_labels = true;
482         _show_annotation_ref_source = true;
483         setAbbreviateScientificTaxonNames( false );
484         _color_labels_same_as_parent_branch = false;
485         _show_confidence_stddev = true;
486         _nh_conversion_support_value_style = NH_CONVERSION_SUPPORT_VALUE_STYLE.NONE;
487         _ext_desc_data_to_return = NODE_DATA.UNKNOWN;
488     }
489
490     final private void setNumberOfDigitsAfterCommaForBranchLength( final short number_of_digits_after_comma_for_branch_length_values ) {
491         _number_of_digits_after_comma_for_branch_length_values = number_of_digits_after_comma_for_branch_length_values;
492     }
493
494     final private void setNumberOfDigitsAfterCommaForConfidenceValues( final short number_of_digits_after_comma_for_confidence_values ) {
495         _number_of_digits_after_comma_for_confidence_values = number_of_digits_after_comma_for_confidence_values;
496     }
497
498     public final static Options createInstance( final Configuration configuration ) {
499         final Options instance = createDefaultInstance();
500         if ( configuration != null ) {
501             instance.setAntialiasScreen( configuration.isAntialiasScreen() );
502             instance.setShowScale( configuration.isShowScale() );
503             instance.setShowBranchLengthValues( configuration.isShowBranchLengthValues() );
504             instance.setShowOverview( configuration.isShowOverview() );
505             instance.setColorByTaxonomicGroup( configuration.isColorByTaxonomicGroup() );
506             instance.setCladogramType( configuration.getCladogramType() );
507             instance.setOvPlacement( configuration.getOvPlacement() );
508             instance.setPrintLineWidth( configuration.getPrintLineWidth() );
509             instance.setNodeLabelDirection( configuration.getNodeLabelDirection() );
510             instance.setBackgroundColorGradient( configuration.isBackgroundColorGradient() );
511             if ( configuration.getNumberOfDigitsAfterCommaForBranchLengthValues() >= 0 ) {
512                 instance.setNumberOfDigitsAfterCommaForBranchLength( configuration
513                         .getNumberOfDigitsAfterCommaForBranchLengthValues() );
514             }
515             if ( configuration.getNumberOfDigitsAfterCommaForConfidenceValues() >= 0 ) {
516                 instance.setNumberOfDigitsAfterCommaForConfidenceValues( configuration
517                         .getNumberOfDigitsAfterCommaForConfidenceValues() );
518             }
519             instance.setTaxonomyExtraction( configuration.getTaxonomyExtraction() );
520             instance.setReplaceUnderscoresInNhParsing( configuration.isReplaceUnderscoresInNhParsing() );
521             instance.setInternalNumberAreConfidenceForNhParsing( configuration
522                     .isInternalNumberAreConfidenceForNhParsing() );
523             instance.setEditable( configuration.isEditable() );
524             instance.setColorLabelsSameAsParentBranch( configuration.isColorLabelsSameAsParentBranch() );
525             instance.setShowDomainLabels( configuration.isShowDomainLabels() );
526             instance.setShowAnnotationRefSource( configuration.isShowAnnotationRefSource() );
527             instance.setAbbreviateScientificTaxonNames( configuration.isAbbreviateScientificTaxonNames() );
528             if ( configuration.getMinConfidenceValue() != MIN_CONFIDENCE_DEFAULT ) {
529                 instance.setMinConfidenceValue( configuration.getMinConfidenceValue() );
530             }
531             if ( configuration.getGraphicsExportX() > 0 ) {
532                 instance.setPrintSizeX( configuration.getGraphicsExportX() );
533             }
534             if ( configuration.getGraphicsExportY() > 0 ) {
535                 instance.setPrintSizeY( configuration.getGraphicsExportY() );
536             }
537             if ( configuration.getBaseFontSize() > 0 ) {
538                 instance.setBaseFont( instance.getBaseFont().deriveFont( ( float ) configuration.getBaseFontSize() ) );
539             }
540             if ( !ForesterUtil.isEmpty( configuration.getBaseFontFamilyName() ) ) {
541                 instance.setBaseFont( new Font( configuration.getBaseFontFamilyName(), Font.PLAIN, instance
542                         .getBaseFont().getSize() ) );
543             }
544             if ( configuration.getPhylogenyGraphicsType() != null ) {
545                 instance.setPhylogenyGraphicsType( configuration.getPhylogenyGraphicsType() );
546             }
547             if ( configuration.getDefaultNodeFill() != null ) {
548                 instance.setDefaultNodeFill( configuration.getDefaultNodeFill() );
549             }
550             if ( configuration.getDefaultNodeShape() != null ) {
551                 instance.setDefaultNodeShape( configuration.getDefaultNodeShape() );
552             }
553             if ( configuration.getDefaultNodeShapeSize() >= 0 ) {
554                 instance.setDefaultNodeShapeSize( configuration.getDefaultNodeShapeSize() );
555             }
556             instance.setTaxonomyColorizeNodeShapes( configuration.isTaxonomyColorizeNodeShapes() );
557             instance.setShowDefaultNodeShapesInternal( configuration.isShowDefaultNodeShapesInternal() );
558             instance.setShowDefaultNodeShapesExternal( configuration.isShowDefaultNodeShapesExternal() );
559             if ( configuration.getExtDescNodeDataToReturn() != null ) {
560                 instance.setExtDescNodeDataToReturn( configuration.getExtDescNodeDataToReturn() );
561             }
562         }
563         return instance;
564     }
565
566     final static Options createDefaultInstance() {
567         return new Options();
568     }
569
570     public static enum CLADOGRAM_TYPE {
571         NON_LINED_UP, EXT_NODE_SUM_DEP, TOTAL_NODE_SUM_DEP;
572     }
573
574     public static enum NODE_LABEL_DIRECTION {
575         HORIZONTAL, RADIAL;
576     }
577
578     public static enum PHYLOGENY_GRAPHICS_TYPE {
579         RECTANGULAR, TRIANGULAR, EURO_STYLE, ROUNDED, CONVEX, CURVED, UNROOTED, CIRCULAR;
580     }
581
582     static enum OVERVIEW_PLACEMENT_TYPE {
583         UPPER_LEFT( "upper left" ),
584         UPPER_RIGHT( "upper right" ),
585         LOWER_LEFT( "lower left" ),
586         LOWER_RIGHT( "lower right" );
587
588         private final String _name;
589
590         private OVERVIEW_PLACEMENT_TYPE( final String name ) {
591             _name = name;
592         }
593
594         @Override
595         public String toString() {
596             return _name;
597         }
598
599         public String toTag() {
600             return toString().replaceAll( " ", "_" );
601         }
602     }
603
604     public boolean isAllowFontSizeChange() {
605         return true;
606     }
607 }