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 boolean isAllowFontSizeChange() {
108 public final boolean isShowAnnotationRefSource() {
109 return _show_annotation_ref_source;
112 public final boolean isShowDomainLabels() {
113 return _show_domain_labels;
116 public final void setAllowErrorsInDistanceToParent( final boolean allow_errors_in_distance_to_parent ) {
117 _allow_errors_in_distance_to_parent = allow_errors_in_distance_to_parent;
120 public void setBackgroundColorGradient( final boolean background_color_gradient ) {
121 _background_color_gradient = background_color_gradient;
124 public void setColorLabelsSameAsParentBranch( final boolean color_labels_same_as_parent_branch ) {
125 _color_labels_same_as_parent_branch = color_labels_same_as_parent_branch;
128 public void setExtDescNodeDataToReturn( final NODE_DATA ext_desc_data_to_return ) {
129 _ext_desc_data_to_return = ext_desc_data_to_return;
132 public final void setShowAnnotationRefSource( final boolean show_annotation_ref_source ) {
133 _show_annotation_ref_source = show_annotation_ref_source;
136 public void setShowDomainLabels( final boolean show_domain_labels ) {
137 _show_domain_labels = show_domain_labels;
140 final Font getBaseFont() {
144 final CLADOGRAM_TYPE getCladogramType() {
145 return _cladogram_type;
148 final NodeFill getDefaultNodeFill() {
149 return _default_node_fill;
152 final NodeShape getDefaultNodeShape() {
153 return _default_node_shape;
156 final short getDefaultNodeShapeSize() {
157 return _default_node_shape_size;
160 final double getMinConfidenceValue() {
161 return _min_confidence_value;
164 NH_CONVERSION_SUPPORT_VALUE_STYLE getNhConversionSupportValueStyle() {
165 return _nh_conversion_support_value_style;
168 final NODE_LABEL_DIRECTION getNodeLabelDirection() {
169 return _node_label_direction;
172 final short getNumberOfDigitsAfterCommaForBranchLengthValues() {
173 return _number_of_digits_after_comma_for_branch_length_values;
176 final short getNumberOfDigitsAfterCommaForConfidenceValues() {
177 return _number_of_digits_after_comma_for_confidence_values;
180 final OVERVIEW_PLACEMENT_TYPE getOvPlacement() {
181 return _ov_placement;
184 final PHYLOGENY_GRAPHICS_TYPE getPhylogenyGraphicsType() {
185 return _phylogeny_graphics_type;
188 final float getPrintLineWidth() {
189 return _print_line_width;
192 final int getPrintSizeX() {
193 return _print_size_x;
196 final int getPrintSizeY() {
197 return _print_size_y;
200 final double getScaleBarLength() {
201 return _scale_bar_length;
204 final TAXONOMY_EXTRACTION getTaxonomyExtraction() {
205 return _taxonomy_extraction;
208 final boolean isAbbreviateScientificTaxonNames() {
209 return _abbreviate_scientific_names;
212 boolean isAllowMagnificationOfTaxonomyImages() {
216 final boolean isAntialiasPrint() {
217 return _antialias_print;
220 final boolean isAntialiasScreen() {
221 return _antialias_screen;
224 final boolean isBackgroundColorGradient() {
225 return _background_color_gradient;
228 final boolean isColorByTaxonomicGroup() {
229 return _color_by_taxonomic_group;
232 final boolean isColorLabelsSameAsParentBranch() {
233 return _color_labels_same_as_parent_branch;
236 final boolean isEditable() {
240 final boolean isGraphicsExportUsingActualSize() {
241 return _graphics_export_using_actual_size;
244 final boolean isGraphicsExportVisibleOnly() {
245 return _graphics_export_visible_only;
248 final boolean isInternalNumberAreConfidenceForNhParsing() {
249 return _internal_number_are_confidence_for_nh_parsing;
252 final boolean isInverseSearchResult() {
253 return _inverse_search_result;
256 final boolean isMatchWholeTermsOnly() {
257 return _match_whole_terms_only;
260 final boolean isSearchWithRegex() {
261 return _search_with_regex;
264 final boolean isPrintBlackAndWhite() {
265 return _print_black_and_white;
268 final boolean isPrintUsingActualSize() {
269 return _print_using_actual_size;
272 final boolean isReplaceUnderscoresInNhParsing() {
273 return _nh_parsing_replace_underscores;
276 final boolean isSearchCaseSensitive() {
277 return _search_case_sensitive;
280 boolean isShowConfidenceStddev() {
281 return _show_confidence_stddev;
284 boolean isShowDefaultNodeShapesExternal() {
285 return _show_default_node_shapes_external;
288 boolean isShowDefaultNodeShapesForMarkedNodes() {
289 return _show_default_node_shapes_for_marked_nodes;
292 boolean isShowDefaultNodeShapesInternal() {
293 return _show_default_node_shapes_internal;
296 final boolean isShowOverview() {
297 return _show_overview;
300 final boolean isShowScale() {
304 final void setAbbreviateScientificTaxonNames( final boolean abbreviate_scientific_names ) {
305 _abbreviate_scientific_names = abbreviate_scientific_names;
308 final void setAntialiasPrint( final boolean antialias_print ) {
309 _antialias_print = antialias_print;
312 final void setAntialiasScreen( final boolean antialias_screen ) {
313 _antialias_screen = antialias_screen;
316 final void setBaseFont( final Font base_font ) {
317 _base_font = base_font;
320 final void setCladogramType( final CLADOGRAM_TYPE cladogram_type ) {
321 _cladogram_type = cladogram_type;
324 final void setColorByTaxonomicGroup( final boolean color_by_taxonomic_group ) {
325 _color_by_taxonomic_group = color_by_taxonomic_group;
328 final void setDefaultNodeFill( final NodeFill default_node_fill ) {
329 _default_node_fill = default_node_fill;
332 final void setDefaultNodeShape( final NodeShape default_node_shape ) {
333 _default_node_shape = default_node_shape;
336 final void setDefaultNodeShapeSize( final short default_node_shape_size ) {
337 _default_node_shape_size = default_node_shape_size;
340 final void setEditable( final boolean editable ) {
341 _editable = editable;
344 final void setGraphicsExportUsingActualSize( final boolean graphics_export_using_actual_size ) {
345 _graphics_export_using_actual_size = graphics_export_using_actual_size;
346 if ( !graphics_export_using_actual_size ) {
347 setGraphicsExportVisibleOnly( false );
351 final void setGraphicsExportVisibleOnly( final boolean graphics_export_visible_only ) {
352 _graphics_export_visible_only = graphics_export_visible_only;
353 if ( graphics_export_visible_only ) {
354 setGraphicsExportUsingActualSize( true );
358 final void setInternalNumberAreConfidenceForNhParsing( final boolean internal_number_are_confidence_for_nh_parsing ) {
359 _internal_number_are_confidence_for_nh_parsing = internal_number_are_confidence_for_nh_parsing;
362 final void setInverseSearchResult( final boolean inverse_search_result ) {
363 _inverse_search_result = inverse_search_result;
366 final void setMatchWholeTermsOnly( final boolean search_whole_words_only ) {
367 _match_whole_terms_only = search_whole_words_only;
370 final void setSearchWithRegex( final boolean search_with_regex ) {
371 _search_with_regex = search_with_regex;
374 final void setMinConfidenceValue( final double min_confidence_value ) {
375 _min_confidence_value = min_confidence_value;
378 void setNhConversionSupportValueStyle( final NH_CONVERSION_SUPPORT_VALUE_STYLE nh_conversion_support_value_style ) {
379 _nh_conversion_support_value_style = nh_conversion_support_value_style;
382 final void setNodeLabelDirection( final NODE_LABEL_DIRECTION node_label_direction ) {
383 _node_label_direction = node_label_direction;
386 final void setOvPlacement( final OVERVIEW_PLACEMENT_TYPE ov_placement ) {
387 _ov_placement = ov_placement;
390 final void setPhylogenyGraphicsType( final PHYLOGENY_GRAPHICS_TYPE phylogeny_graphics_type ) {
391 _phylogeny_graphics_type = phylogeny_graphics_type;
394 final void setPrintBlackAndWhite( final boolean print_black_and_white ) {
395 _print_black_and_white = print_black_and_white;
398 final void setPrintLineWidth( final float print_line_width ) {
399 _print_line_width = print_line_width;
402 final void setPrintSizeX( final int print_size_x ) {
403 _print_size_x = print_size_x;
406 final void setPrintSizeY( final int print_size_y ) {
407 _print_size_y = print_size_y;
410 final void setPrintUsingActualSize( final boolean print_using_actual_size ) {
411 _print_using_actual_size = print_using_actual_size;
414 final void setReplaceUnderscoresInNhParsing( final boolean nh_parsing_replace_underscores ) {
415 _nh_parsing_replace_underscores = nh_parsing_replace_underscores;
418 final void setScaleBarLength( final double scale_bar_length ) {
419 _scale_bar_length = scale_bar_length;
422 final void setSearchCaseSensitive( final boolean search_case_sensitive ) {
423 _search_case_sensitive = search_case_sensitive;
426 void setShowConfidenceStddev( final boolean show_confidence_stddev ) {
427 _show_confidence_stddev = show_confidence_stddev;
430 void setShowDefaultNodeShapesExternal( final boolean show_default_node_shapes_external ) {
431 _show_default_node_shapes_external = show_default_node_shapes_external;
434 void setShowDefaultNodeShapesInternal( final boolean show_default_node_shapes_internal ) {
435 _show_default_node_shapes_internal = show_default_node_shapes_internal;
438 void setShowDefaultNodeShapesForMarkedNodes( final boolean show_default_node_shapes_for_marked_nodes ) {
439 _show_default_node_shapes_for_marked_nodes = show_default_node_shapes_for_marked_nodes;
442 final void setShowOverview( final boolean show_overview ) {
443 _show_overview = show_overview;
446 final void setShowScale( final boolean show_scale ) {
447 _show_scale = show_scale;
450 final void setTaxonomyExtraction( final TAXONOMY_EXTRACTION taxonomy_extraction ) {
451 _taxonomy_extraction = taxonomy_extraction;
454 final private void init() {
455 _default_node_shape = NodeShape.CIRCLE;
456 _default_node_fill = NodeFill.GRADIENT;
457 _default_node_shape_size = Constants.DEFAULT_NODE_SHAPE_SIZE_DEFAULT;
458 _internal_number_are_confidence_for_nh_parsing = false;
460 _antialias_screen = true;
461 _antialias_print = true;
462 _graphics_export_visible_only = false;
464 _background_color_gradient = false;
465 _show_default_node_shapes_internal = false;
466 _show_default_node_shapes_external = false;
467 _show_default_node_shapes_for_marked_nodes = false;
468 if ( AptxUtil.isUsOrCanada() ) {
469 _print_size_x = Constants.US_LETTER_SIZE_X;
470 _print_size_y = Constants.US_LETTER_SIZE_Y;
473 _print_size_x = Constants.A4_SIZE_X;
474 _print_size_y = Constants.A4_SIZE_Y;
476 _min_confidence_value = MIN_CONFIDENCE_DEFAULT;
477 _print_black_and_white = false;
478 _print_using_actual_size = true;
479 _graphics_export_using_actual_size = true;
480 _phylogeny_graphics_type = PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR;
481 _base_font = new Font( Configuration.getDefaultFontFamilyName(), Font.PLAIN, 10 );
482 _match_whole_terms_only = false;
483 _search_with_regex = false;
484 _search_case_sensitive = true;
485 _print_line_width = Constants.PDF_LINE_WIDTH_DEFAULT;
486 _show_overview = true;
487 _ov_placement = OVERVIEW_PLACEMENT_TYPE.UPPER_LEFT;
488 _node_label_direction = NODE_LABEL_DIRECTION.HORIZONTAL;
489 _inverse_search_result = false;
490 _scale_bar_length = 0.0;
491 _number_of_digits_after_comma_for_branch_length_values = Constants.NUMBER_OF_DIGITS_AFTER_COMMA_FOR_BRANCH_LENGTH_VALUES_DEFAULT;
492 _number_of_digits_after_comma_for_confidence_values = Constants.NUMBER_OF_DIGITS_AFTER_COMMA_FOR_CONFIDENCE_VALUES_DEFAULT;
493 _nh_parsing_replace_underscores = false;
494 _taxonomy_extraction = TAXONOMY_EXTRACTION.NO;
495 _cladogram_type = Constants.CLADOGRAM_TYPE_DEFAULT;
496 _show_domain_labels = true;
497 _show_annotation_ref_source = true;
498 setAbbreviateScientificTaxonNames( false );
499 _color_labels_same_as_parent_branch = false;
500 _show_confidence_stddev = false;
501 _nh_conversion_support_value_style = NH_CONVERSION_SUPPORT_VALUE_STYLE.NONE;
502 _ext_desc_data_to_return = NODE_DATA.UNKNOWN;
503 _line_up_renderable_node_data = true;
504 _right_align_domains = false;
507 final private void setNumberOfDigitsAfterCommaForBranchLength( final short number_of_digits_after_comma_for_branch_length_values ) {
508 _number_of_digits_after_comma_for_branch_length_values = number_of_digits_after_comma_for_branch_length_values;
511 final private void setNumberOfDigitsAfterCommaForConfidenceValues( final short number_of_digits_after_comma_for_confidence_values ) {
512 _number_of_digits_after_comma_for_confidence_values = number_of_digits_after_comma_for_confidence_values;
515 public final static Options createInstance( final Configuration configuration ) {
516 final Options instance = createDefaultInstance();
517 if ( configuration != null ) {
518 instance.setAntialiasScreen( configuration.isAntialiasScreen() );
519 instance.setShowScale( configuration.isShowScale() );
520 instance.setShowOverview( configuration.isShowOverview() );
521 instance.setColorByTaxonomicGroup( configuration.isColorByTaxonomicGroup() );
522 instance.setCladogramType( configuration.getCladogramType() );
523 instance.setOvPlacement( configuration.getOvPlacement() );
524 instance.setPrintLineWidth( configuration.getPrintLineWidth() );
525 instance.setNodeLabelDirection( configuration.getNodeLabelDirection() );
526 instance.setBackgroundColorGradient( configuration.isBackgroundColorGradient() );
527 if ( configuration.getNumberOfDigitsAfterCommaForBranchLengthValues() >= 0 ) {
528 instance.setNumberOfDigitsAfterCommaForBranchLength( configuration
529 .getNumberOfDigitsAfterCommaForBranchLengthValues() );
531 if ( configuration.getNumberOfDigitsAfterCommaForConfidenceValues() >= 0 ) {
532 instance.setNumberOfDigitsAfterCommaForConfidenceValues( configuration
533 .getNumberOfDigitsAfterCommaForConfidenceValues() );
535 instance.setTaxonomyExtraction( configuration.getTaxonomyExtraction() );
536 instance.setReplaceUnderscoresInNhParsing( configuration.isReplaceUnderscoresInNhParsing() );
537 instance.setInternalNumberAreConfidenceForNhParsing( configuration
538 .isInternalNumberAreConfidenceForNhParsing() );
539 instance.setEditable( configuration.isEditable() );
540 instance.setColorLabelsSameAsParentBranch( configuration.isColorLabelsSameAsParentBranch() );
541 instance.setShowDomainLabels( configuration.isShowDomainLabels() );
542 instance.setShowAnnotationRefSource( configuration.isShowAnnotationRefSource() );
543 instance.setAbbreviateScientificTaxonNames( configuration.isAbbreviateScientificTaxonNames() );
544 if ( configuration.getMinConfidenceValue() != MIN_CONFIDENCE_DEFAULT ) {
545 instance.setMinConfidenceValue( configuration.getMinConfidenceValue() );
547 if ( configuration.getGraphicsExportX() > 0 ) {
548 instance.setPrintSizeX( configuration.getGraphicsExportX() );
550 if ( configuration.getGraphicsExportY() > 0 ) {
551 instance.setPrintSizeY( configuration.getGraphicsExportY() );
553 if ( configuration.getBaseFontSize() > 0 ) {
554 instance.setBaseFont( instance.getBaseFont().deriveFont( ( float ) configuration.getBaseFontSize() ) );
556 if ( !ForesterUtil.isEmpty( configuration.getBaseFontFamilyName() ) ) {
557 instance.setBaseFont( new Font( configuration.getBaseFontFamilyName(), Font.PLAIN, instance
558 .getBaseFont().getSize() ) );
560 if ( configuration.getPhylogenyGraphicsType() != null ) {
561 instance.setPhylogenyGraphicsType( configuration.getPhylogenyGraphicsType() );
563 if ( configuration.getDefaultNodeFill() != null ) {
564 instance.setDefaultNodeFill( configuration.getDefaultNodeFill() );
566 if ( configuration.getDefaultNodeShape() != null ) {
567 instance.setDefaultNodeShape( configuration.getDefaultNodeShape() );
569 if ( configuration.getDefaultNodeShapeSize() >= 0 ) {
570 instance.setDefaultNodeShapeSize( configuration.getDefaultNodeShapeSize() );
572 instance.setShowDefaultNodeShapesInternal( configuration.isShowDefaultNodeShapesInternal() );
573 instance.setShowDefaultNodeShapesExternal( configuration.isShowDefaultNodeShapesExternal() );
574 instance.setShowDefaultNodeShapesForMarkedNodes( configuration.isShowDefaultNodeShapesForMarkedNodes() );
575 if ( configuration.getExtDescNodeDataToReturn() != null ) {
576 instance.setExtDescNodeDataToReturn( configuration.getExtDescNodeDataToReturn() );
578 instance.setRightLineUpDomains( configuration.isRightLineUpDomains() );
579 instance.setLineUpRendarableNodeData( configuration.isLineUpRendarableNodeData() );
580 instance.setAllowErrorsInDistanceToParent( false );
585 final static Options createDefaultInstance() {
586 return new Options();
589 public static enum CLADOGRAM_TYPE {
590 EXT_NODE_SUM_DEP, NON_LINED_UP, TOTAL_NODE_SUM_DEP;
593 public static enum NODE_LABEL_DIRECTION {
597 public static enum PHYLOGENY_GRAPHICS_TYPE {
598 CIRCULAR, CONVEX, CURVED, EURO_STYLE, RECTANGULAR, ROUNDED, TRIANGULAR, UNROOTED;
601 static enum OVERVIEW_PLACEMENT_TYPE {
602 LOWER_LEFT( "lower left" ),
603 LOWER_RIGHT( "lower right" ),
604 UPPER_LEFT( "upper left" ),
605 UPPER_RIGHT( "upper right" );
607 private final String _name;
609 private OVERVIEW_PLACEMENT_TYPE( final String name ) {
614 public String toString() {
618 public String toTag() {
619 return toString().replaceAll( " ", "_" );
623 final public boolean isLineUpRendarableNodeData() {
624 return _line_up_renderable_node_data;
627 final public boolean isRightLineUpDomains() {
628 return _right_align_domains;
631 final public void setLineUpRendarableNodeData( final boolean line_up_renderable_node_data ) {
632 _line_up_renderable_node_data = line_up_renderable_node_data;
635 final public void setRightLineUpDomains( final boolean right_align_domains ) {
636 _right_align_domains = right_align_domains;