2 // FORESTER -- software libraries and applications
3 // for evolutionary biology research and applications.
5 // Copyright (C) 2009 Christian M. Zmasek
6 // Copyright (C) 2009 Burnham Institute for Medical Research
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.
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.
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
23 // Contact: phylosoft @ gmail . com
24 // WWW: https://sites.google.com/site/cmzmasek/home/software/forester
26 package org.forester.archaeopteryx;
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.NodeVisualData;
35 import org.forester.phylogeny.data.NodeVisualData.NodeFill;
36 import org.forester.phylogeny.data.NodeVisualData.NodeShape;
37 import org.forester.util.ForesterUtil;
40 * This is to hold changeable options.
42 final public class Options {
44 static final double MIN_CONFIDENCE_DEFAULT = 0.0;
45 private boolean _abbreviate_scientific_names;
46 private boolean _allow_errors_in_distance_to_parent;
47 private boolean _antialias_print;
48 private boolean _antialias_screen;
49 private boolean _background_color_gradient;
50 private Font _base_font;
51 private CLADOGRAM_TYPE _cladogram_type;
52 private boolean _color_by_taxonomic_group;
53 private boolean _color_labels_same_as_parent_branch;
54 private NodeVisualData.NodeFill _default_node_fill;
55 private NodeVisualData.NodeShape _default_node_shape;
56 private short _default_node_shape_size;
57 private boolean _editable;
58 private NODE_DATA _ext_desc_data_to_return;
59 private boolean _graphics_export_using_actual_size;
60 private boolean _graphics_export_visible_only;
61 private boolean _internal_number_are_confidence_for_nh_parsing;
62 private boolean _inverse_search_result;
63 private boolean _match_whole_terms_only;
64 private boolean _search_with_regex;
65 private double _min_confidence_value;
66 private NH_CONVERSION_SUPPORT_VALUE_STYLE _nh_conversion_support_value_style;
67 private boolean _nh_parsing_replace_underscores;
68 private NODE_LABEL_DIRECTION _node_label_direction;
69 private short _number_of_digits_after_comma_for_branch_length_values;
70 private short _number_of_digits_after_comma_for_confidence_values;
71 private OVERVIEW_PLACEMENT_TYPE _ov_placement;
72 private PHYLOGENY_GRAPHICS_TYPE _phylogeny_graphics_type;
73 private boolean _print_black_and_white;
74 private float _print_line_width;
75 private int _print_size_x;
76 private int _print_size_y;
77 private boolean _print_using_actual_size;
78 private double _scale_bar_length;
79 private boolean _search_case_sensitive;
80 private boolean _show_annotation_ref_source;
81 private boolean _show_confidence_stddev;
82 private boolean _show_default_node_shapes_for_marked_nodes;
83 private boolean _show_default_node_shapes_external;
84 private boolean _show_default_node_shapes_internal;
85 private boolean _show_domain_labels;
86 private boolean _show_overview;
87 private boolean _show_scale;
88 private TAXONOMY_EXTRACTION _taxonomy_extraction;
89 private boolean _line_up_renderable_node_data;
90 private boolean _right_align_domains;
96 public NodeData.NODE_DATA getExtDescNodeDataToReturn() {
97 return _ext_desc_data_to_return;
100 public boolean isAllowErrorsInDistanceToParent() {
101 return _allow_errors_in_distance_to_parent;
104 public final boolean isShowAnnotationRefSource() {
105 return _show_annotation_ref_source;
108 public final boolean isShowDomainLabels() {
109 return _show_domain_labels;
112 public final void setAllowErrorsInDistanceToParent( final boolean allow_errors_in_distance_to_parent ) {
113 _allow_errors_in_distance_to_parent = allow_errors_in_distance_to_parent;
116 public void setBackgroundColorGradient( final boolean background_color_gradient ) {
117 _background_color_gradient = background_color_gradient;
120 public void setColorLabelsSameAsParentBranch( final boolean color_labels_same_as_parent_branch ) {
121 _color_labels_same_as_parent_branch = color_labels_same_as_parent_branch;
124 public void setExtDescNodeDataToReturn( final NODE_DATA ext_desc_data_to_return ) {
125 _ext_desc_data_to_return = ext_desc_data_to_return;
128 public final void setShowAnnotationRefSource( final boolean show_annotation_ref_source ) {
129 _show_annotation_ref_source = show_annotation_ref_source;
132 public void setShowDomainLabels( final boolean show_domain_labels ) {
133 _show_domain_labels = show_domain_labels;
136 final Font getBaseFont() {
140 final CLADOGRAM_TYPE getCladogramType() {
141 return _cladogram_type;
144 final NodeFill getDefaultNodeFill() {
145 return _default_node_fill;
148 final NodeShape getDefaultNodeShape() {
149 return _default_node_shape;
152 final short getDefaultNodeShapeSize() {
153 return _default_node_shape_size;
156 final double getMinConfidenceValue() {
157 return _min_confidence_value;
160 NH_CONVERSION_SUPPORT_VALUE_STYLE getNhConversionSupportValueStyle() {
161 return _nh_conversion_support_value_style;
164 final NODE_LABEL_DIRECTION getNodeLabelDirection() {
165 return _node_label_direction;
168 final short getNumberOfDigitsAfterCommaForBranchLengthValues() {
169 return _number_of_digits_after_comma_for_branch_length_values;
172 final short getNumberOfDigitsAfterCommaForConfidenceValues() {
173 return _number_of_digits_after_comma_for_confidence_values;
176 final OVERVIEW_PLACEMENT_TYPE getOvPlacement() {
177 return _ov_placement;
180 final PHYLOGENY_GRAPHICS_TYPE getPhylogenyGraphicsType() {
181 return _phylogeny_graphics_type;
184 final float getPrintLineWidth() {
185 return _print_line_width;
188 final int getPrintSizeX() {
189 return _print_size_x;
192 final int getPrintSizeY() {
193 return _print_size_y;
196 final double getScaleBarLength() {
197 return _scale_bar_length;
200 final TAXONOMY_EXTRACTION getTaxonomyExtraction() {
201 return _taxonomy_extraction;
204 final boolean isAbbreviateScientificTaxonNames() {
205 return _abbreviate_scientific_names;
208 boolean isAllowMagnificationOfTaxonomyImages() {
212 final boolean isAntialiasPrint() {
213 return _antialias_print;
216 final boolean isAntialiasScreen() {
217 return _antialias_screen;
220 final boolean isBackgroundColorGradient() {
221 return _background_color_gradient;
224 final boolean isColorByTaxonomicGroup() {
225 return _color_by_taxonomic_group;
228 final boolean isColorLabelsSameAsParentBranch() {
229 return _color_labels_same_as_parent_branch;
232 final boolean isEditable() {
236 final boolean isGraphicsExportUsingActualSize() {
237 return _graphics_export_using_actual_size;
240 final boolean isGraphicsExportVisibleOnly() {
241 return _graphics_export_visible_only;
244 final boolean isInternalNumberAreConfidenceForNhParsing() {
245 return _internal_number_are_confidence_for_nh_parsing;
248 final boolean isInverseSearchResult() {
249 return _inverse_search_result;
252 final boolean isMatchWholeTermsOnly() {
253 return _match_whole_terms_only;
256 final boolean isSearchWithRegex() {
257 return _search_with_regex;
260 final boolean isPrintBlackAndWhite() {
261 return _print_black_and_white;
264 final boolean isPrintUsingActualSize() {
265 return _print_using_actual_size;
268 final boolean isReplaceUnderscoresInNhParsing() {
269 return _nh_parsing_replace_underscores;
272 final boolean isSearchCaseSensitive() {
273 return _search_case_sensitive;
276 boolean isShowConfidenceStddev() {
277 return _show_confidence_stddev;
280 boolean isShowDefaultNodeShapesExternal() {
281 return _show_default_node_shapes_external;
284 boolean isShowDefaultNodeShapesForMarkedNodes() {
285 return _show_default_node_shapes_for_marked_nodes;
288 boolean isShowDefaultNodeShapesInternal() {
289 return _show_default_node_shapes_internal;
292 final boolean isShowOverview() {
293 return _show_overview;
296 final boolean isShowScale() {
300 final void setAbbreviateScientificTaxonNames( final boolean abbreviate_scientific_names ) {
301 _abbreviate_scientific_names = abbreviate_scientific_names;
304 final void setAntialiasPrint( final boolean antialias_print ) {
305 _antialias_print = antialias_print;
308 final void setAntialiasScreen( final boolean antialias_screen ) {
309 _antialias_screen = antialias_screen;
312 final void setBaseFont( final Font base_font ) {
313 _base_font = base_font;
316 final void setCladogramType( final CLADOGRAM_TYPE cladogram_type ) {
317 _cladogram_type = cladogram_type;
320 final void setColorByTaxonomicGroup( final boolean color_by_taxonomic_group ) {
321 _color_by_taxonomic_group = color_by_taxonomic_group;
324 final void setDefaultNodeFill( final NodeFill default_node_fill ) {
325 _default_node_fill = default_node_fill;
328 final void setDefaultNodeShape( final NodeShape default_node_shape ) {
329 _default_node_shape = default_node_shape;
332 final void setDefaultNodeShapeSize( final short default_node_shape_size ) {
333 _default_node_shape_size = default_node_shape_size;
336 final void setEditable( final boolean editable ) {
337 _editable = editable;
340 final void setGraphicsExportUsingActualSize( final boolean graphics_export_using_actual_size ) {
341 _graphics_export_using_actual_size = graphics_export_using_actual_size;
342 if ( !graphics_export_using_actual_size ) {
343 setGraphicsExportVisibleOnly( false );
347 final void setGraphicsExportVisibleOnly( final boolean graphics_export_visible_only ) {
348 _graphics_export_visible_only = graphics_export_visible_only;
349 if ( graphics_export_visible_only ) {
350 setGraphicsExportUsingActualSize( true );
354 final void setInternalNumberAreConfidenceForNhParsing( final boolean internal_number_are_confidence_for_nh_parsing ) {
355 _internal_number_are_confidence_for_nh_parsing = internal_number_are_confidence_for_nh_parsing;
358 final void setInverseSearchResult( final boolean inverse_search_result ) {
359 _inverse_search_result = inverse_search_result;
362 final void setMatchWholeTermsOnly( final boolean search_whole_words_only ) {
363 _match_whole_terms_only = search_whole_words_only;
366 final void setSearchWithRegex( final boolean search_with_regex ) {
367 _search_with_regex = search_with_regex;
370 final void setMinConfidenceValue( final double min_confidence_value ) {
371 _min_confidence_value = min_confidence_value;
374 void setNhConversionSupportValueStyle( final NH_CONVERSION_SUPPORT_VALUE_STYLE nh_conversion_support_value_style ) {
375 _nh_conversion_support_value_style = nh_conversion_support_value_style;
378 final void setNodeLabelDirection( final NODE_LABEL_DIRECTION node_label_direction ) {
379 _node_label_direction = node_label_direction;
382 final void setOvPlacement( final OVERVIEW_PLACEMENT_TYPE ov_placement ) {
383 _ov_placement = ov_placement;
386 final void setPhylogenyGraphicsType( final PHYLOGENY_GRAPHICS_TYPE phylogeny_graphics_type ) {
387 _phylogeny_graphics_type = phylogeny_graphics_type;
390 final void setPrintBlackAndWhite( final boolean print_black_and_white ) {
391 _print_black_and_white = print_black_and_white;
394 final void setPrintLineWidth( final float print_line_width ) {
395 _print_line_width = print_line_width;
398 final void setPrintSizeX( final int print_size_x ) {
399 _print_size_x = print_size_x;
402 final void setPrintSizeY( final int print_size_y ) {
403 _print_size_y = print_size_y;
406 final void setPrintUsingActualSize( final boolean print_using_actual_size ) {
407 _print_using_actual_size = print_using_actual_size;
410 final void setReplaceUnderscoresInNhParsing( final boolean nh_parsing_replace_underscores ) {
411 _nh_parsing_replace_underscores = nh_parsing_replace_underscores;
414 final void setScaleBarLength( final double scale_bar_length ) {
415 _scale_bar_length = scale_bar_length;
418 final void setSearchCaseSensitive( final boolean search_case_sensitive ) {
419 _search_case_sensitive = search_case_sensitive;
422 void setShowConfidenceStddev( final boolean show_confidence_stddev ) {
423 _show_confidence_stddev = show_confidence_stddev;
426 void setShowDefaultNodeShapesExternal( final boolean show_default_node_shapes_external ) {
427 _show_default_node_shapes_external = show_default_node_shapes_external;
430 void setShowDefaultNodeShapesInternal( final boolean show_default_node_shapes_internal ) {
431 _show_default_node_shapes_internal = show_default_node_shapes_internal;
434 void setShowDefaultNodeShapesForMarkedNodes( final boolean show_default_node_shapes_for_marked_nodes ) {
435 _show_default_node_shapes_for_marked_nodes = show_default_node_shapes_for_marked_nodes;
438 final void setShowOverview( final boolean show_overview ) {
439 _show_overview = show_overview;
442 final void setShowScale( final boolean show_scale ) {
443 _show_scale = show_scale;
446 final void setTaxonomyExtraction( final TAXONOMY_EXTRACTION taxonomy_extraction ) {
447 _taxonomy_extraction = taxonomy_extraction;
450 final private void init() {
451 _default_node_shape = NodeShape.CIRCLE;
452 _default_node_fill = NodeFill.GRADIENT;
453 _default_node_shape_size = Constants.DEFAULT_NODE_SHAPE_SIZE_DEFAULT;
454 _internal_number_are_confidence_for_nh_parsing = false;
456 _antialias_screen = true;
457 _antialias_print = true;
458 _graphics_export_visible_only = false;
460 _background_color_gradient = false;
461 _show_default_node_shapes_internal = false;
462 _show_default_node_shapes_external = false;
463 _show_default_node_shapes_for_marked_nodes = false;
464 if ( AptxUtil.isUsOrCanada() ) {
465 _print_size_x = Constants.US_LETTER_SIZE_X;
466 _print_size_y = Constants.US_LETTER_SIZE_Y;
469 _print_size_x = Constants.A4_SIZE_X;
470 _print_size_y = Constants.A4_SIZE_Y;
472 _min_confidence_value = MIN_CONFIDENCE_DEFAULT;
473 _print_black_and_white = false;
474 _print_using_actual_size = true;
475 _graphics_export_using_actual_size = true;
476 _phylogeny_graphics_type = PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR;
477 _base_font = new Font( Configuration.getDefaultFontFamilyName(), Font.PLAIN, 10 );
478 _match_whole_terms_only = false;
479 _search_with_regex = false;
480 _search_case_sensitive = true;
481 _print_line_width = Constants.PDF_LINE_WIDTH_DEFAULT;
482 _show_overview = true;
483 _ov_placement = OVERVIEW_PLACEMENT_TYPE.UPPER_LEFT;
484 _node_label_direction = NODE_LABEL_DIRECTION.HORIZONTAL;
485 _inverse_search_result = false;
486 _scale_bar_length = 0.0;
487 _number_of_digits_after_comma_for_branch_length_values = Constants.NUMBER_OF_DIGITS_AFTER_COMMA_FOR_BRANCH_LENGTH_VALUES_DEFAULT;
488 _number_of_digits_after_comma_for_confidence_values = Constants.NUMBER_OF_DIGITS_AFTER_COMMA_FOR_CONFIDENCE_VALUES_DEFAULT;
489 _nh_parsing_replace_underscores = false;
490 _taxonomy_extraction = TAXONOMY_EXTRACTION.NO;
491 _cladogram_type = Constants.CLADOGRAM_TYPE_DEFAULT;
492 _show_domain_labels = true;
493 _show_annotation_ref_source = true;
494 setAbbreviateScientificTaxonNames( false );
495 _color_labels_same_as_parent_branch = false;
496 _show_confidence_stddev = false;
497 _nh_conversion_support_value_style = NH_CONVERSION_SUPPORT_VALUE_STYLE.NONE;
498 _ext_desc_data_to_return = NODE_DATA.UNKNOWN;
499 _line_up_renderable_node_data = true;
500 _right_align_domains = false;
503 final private void setNumberOfDigitsAfterCommaForBranchLength( final short number_of_digits_after_comma_for_branch_length_values ) {
504 _number_of_digits_after_comma_for_branch_length_values = number_of_digits_after_comma_for_branch_length_values;
507 final private void setNumberOfDigitsAfterCommaForConfidenceValues( final short number_of_digits_after_comma_for_confidence_values ) {
508 _number_of_digits_after_comma_for_confidence_values = number_of_digits_after_comma_for_confidence_values;
511 public final static Options createInstance( final Configuration configuration ) {
512 final Options instance = createDefaultInstance();
513 if ( configuration != null ) {
514 instance.setAntialiasScreen( configuration.isAntialiasScreen() );
515 instance.setShowScale( configuration.isShowScale() );
516 instance.setShowOverview( configuration.isShowOverview() );
517 instance.setColorByTaxonomicGroup( configuration.isColorByTaxonomicGroup() );
518 instance.setCladogramType( configuration.getCladogramType() );
519 instance.setOvPlacement( configuration.getOvPlacement() );
520 instance.setPrintLineWidth( configuration.getPrintLineWidth() );
521 instance.setNodeLabelDirection( configuration.getNodeLabelDirection() );
522 instance.setBackgroundColorGradient( configuration.isBackgroundColorGradient() );
523 if ( configuration.getNumberOfDigitsAfterCommaForBranchLengthValues() >= 0 ) {
524 instance.setNumberOfDigitsAfterCommaForBranchLength( configuration
525 .getNumberOfDigitsAfterCommaForBranchLengthValues() );
527 if ( configuration.getNumberOfDigitsAfterCommaForConfidenceValues() >= 0 ) {
528 instance.setNumberOfDigitsAfterCommaForConfidenceValues( configuration
529 .getNumberOfDigitsAfterCommaForConfidenceValues() );
531 instance.setTaxonomyExtraction( configuration.getTaxonomyExtraction() );
532 instance.setReplaceUnderscoresInNhParsing( configuration.isReplaceUnderscoresInNhParsing() );
533 instance.setInternalNumberAreConfidenceForNhParsing( configuration
534 .isInternalNumberAreConfidenceForNhParsing() );
535 instance.setEditable( configuration.isEditable() );
536 instance.setColorLabelsSameAsParentBranch( configuration.isColorLabelsSameAsParentBranch() );
537 instance.setShowDomainLabels( configuration.isShowDomainLabels() );
538 instance.setShowAnnotationRefSource( configuration.isShowAnnotationRefSource() );
539 instance.setAbbreviateScientificTaxonNames( configuration.isAbbreviateScientificTaxonNames() );
540 if ( configuration.getMinConfidenceValue() != MIN_CONFIDENCE_DEFAULT ) {
541 instance.setMinConfidenceValue( configuration.getMinConfidenceValue() );
543 if ( configuration.getGraphicsExportX() > 0 ) {
544 instance.setPrintSizeX( configuration.getGraphicsExportX() );
546 if ( configuration.getGraphicsExportY() > 0 ) {
547 instance.setPrintSizeY( configuration.getGraphicsExportY() );
549 if ( configuration.getBaseFontSize() > 0 ) {
550 instance.setBaseFont( instance.getBaseFont().deriveFont( ( float ) configuration.getBaseFontSize() ) );
552 if ( !ForesterUtil.isEmpty( configuration.getBaseFontFamilyName() ) ) {
553 instance.setBaseFont( new Font( configuration.getBaseFontFamilyName(), Font.PLAIN, instance
554 .getBaseFont().getSize() ) );
556 if ( configuration.getPhylogenyGraphicsType() != null ) {
557 instance.setPhylogenyGraphicsType( configuration.getPhylogenyGraphicsType() );
559 if ( configuration.getDefaultNodeFill() != null ) {
560 instance.setDefaultNodeFill( configuration.getDefaultNodeFill() );
562 if ( configuration.getDefaultNodeShape() != null ) {
563 instance.setDefaultNodeShape( configuration.getDefaultNodeShape() );
565 if ( configuration.getDefaultNodeShapeSize() >= 0 ) {
566 instance.setDefaultNodeShapeSize( configuration.getDefaultNodeShapeSize() );
568 instance.setShowDefaultNodeShapesInternal( configuration.isShowDefaultNodeShapesInternal() );
569 instance.setShowDefaultNodeShapesExternal( configuration.isShowDefaultNodeShapesExternal() );
570 instance.setShowDefaultNodeShapesForMarkedNodes( configuration.isShowDefaultNodeShapesForMarkedNodes() );
571 if ( configuration.getExtDescNodeDataToReturn() != null ) {
572 instance.setExtDescNodeDataToReturn( configuration.getExtDescNodeDataToReturn() );
574 instance.setRightLineUpDomains( configuration.isRightLineUpDomains() );
575 instance.setLineUpRendarableNodeData( configuration.isLineUpRendarableNodeData() );
576 instance.setAllowErrorsInDistanceToParent( false );
581 final static Options createDefaultInstance() {
582 return new Options();
585 public static enum CLADOGRAM_TYPE {
586 EXT_NODE_SUM_DEP, NON_LINED_UP, TOTAL_NODE_SUM_DEP;
589 public static enum NODE_LABEL_DIRECTION {
593 public static enum PHYLOGENY_GRAPHICS_TYPE {
594 CIRCULAR, CONVEX, CURVED, EURO_STYLE, RECTANGULAR, ROUNDED, TRIANGULAR, UNROOTED;
597 static enum OVERVIEW_PLACEMENT_TYPE {
598 LOWER_LEFT( "lower left" ),
599 LOWER_RIGHT( "lower right" ),
600 UPPER_LEFT( "upper left" ),
601 UPPER_RIGHT( "upper right" );
603 private final String _name;
605 private OVERVIEW_PLACEMENT_TYPE( final String name ) {
610 public String toString() {
614 public String toTag() {
615 return toString().replaceAll( " ", "_" );
619 final public boolean isLineUpRendarableNodeData() {
620 return _line_up_renderable_node_data;
623 final public boolean isRightLineUpDomains() {
624 return _right_align_domains;
627 final public void setLineUpRendarableNodeData( final boolean line_up_renderable_node_data ) {
628 _line_up_renderable_node_data = line_up_renderable_node_data;
631 final public void setRightLineUpDomains( final boolean right_align_domains ) {
632 _right_align_domains = right_align_domains;