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 double _min_confidence_value;
65 private NH_CONVERSION_SUPPORT_VALUE_STYLE _nh_conversion_support_value_style;
66 private boolean _nh_parsing_replace_underscores;
67 private NODE_LABEL_DIRECTION _node_label_direction;
68 private short _number_of_digits_after_comma_for_branch_length_values;
69 private short _number_of_digits_after_comma_for_confidence_values;
70 private OVERVIEW_PLACEMENT_TYPE _ov_placement;
71 private PHYLOGENY_GRAPHICS_TYPE _phylogeny_graphics_type;
72 private boolean _print_black_and_white;
73 private float _print_line_width;
74 private int _print_size_x;
75 private int _print_size_y;
76 private boolean _print_using_actual_size;
77 private double _scale_bar_length;
78 private boolean _search_case_sensitive;
79 private boolean _show_annotation_ref_source;
80 private boolean _show_branch_length_values;
81 private boolean _show_confidence_stddev;
82 private boolean _show_default_node_shapes_external;
83 private boolean _show_default_node_shapes_internal;
84 private boolean _show_domain_labels;
85 private boolean _show_overview;
86 private boolean _show_scale;
87 private TAXONOMY_EXTRACTION _taxonomy_extraction;
88 private boolean _line_up_renderable_node_data;
89 private boolean _right_align_domains;
95 public NodeData.NODE_DATA getExtDescNodeDataToReturn() {
96 return _ext_desc_data_to_return;
99 public boolean isAllowErrorsInDistanceToParent() {
100 return _allow_errors_in_distance_to_parent;
103 public boolean isAllowFontSizeChange() {
107 public final boolean isShowAnnotationRefSource() {
108 return _show_annotation_ref_source;
111 public final boolean isShowDomainLabels() {
112 return _show_domain_labels;
115 public final void setAllowErrorsInDistanceToParent( final boolean allow_errors_in_distance_to_parent ) {
116 _allow_errors_in_distance_to_parent = allow_errors_in_distance_to_parent;
119 public void setBackgroundColorGradient( final boolean background_color_gradient ) {
120 _background_color_gradient = background_color_gradient;
123 public void setColorLabelsSameAsParentBranch( final boolean color_labels_same_as_parent_branch ) {
124 _color_labels_same_as_parent_branch = color_labels_same_as_parent_branch;
127 public void setExtDescNodeDataToReturn( final NODE_DATA ext_desc_data_to_return ) {
128 _ext_desc_data_to_return = ext_desc_data_to_return;
131 public final void setShowAnnotationRefSource( final boolean show_annotation_ref_source ) {
132 _show_annotation_ref_source = show_annotation_ref_source;
135 public void setShowDomainLabels( final boolean show_domain_labels ) {
136 _show_domain_labels = show_domain_labels;
139 final Font getBaseFont() {
143 final CLADOGRAM_TYPE getCladogramType() {
144 return _cladogram_type;
147 final NodeFill getDefaultNodeFill() {
148 return _default_node_fill;
151 final NodeShape getDefaultNodeShape() {
152 return _default_node_shape;
155 final short getDefaultNodeShapeSize() {
156 return _default_node_shape_size;
159 final double getMinConfidenceValue() {
160 return _min_confidence_value;
163 NH_CONVERSION_SUPPORT_VALUE_STYLE getNhConversionSupportValueStyle() {
164 return _nh_conversion_support_value_style;
167 final NODE_LABEL_DIRECTION getNodeLabelDirection() {
168 return _node_label_direction;
171 final short getNumberOfDigitsAfterCommaForBranchLengthValues() {
172 return _number_of_digits_after_comma_for_branch_length_values;
175 final short getNumberOfDigitsAfterCommaForConfidenceValues() {
176 return _number_of_digits_after_comma_for_confidence_values;
179 final OVERVIEW_PLACEMENT_TYPE getOvPlacement() {
180 return _ov_placement;
183 final PHYLOGENY_GRAPHICS_TYPE getPhylogenyGraphicsType() {
184 return _phylogeny_graphics_type;
187 final float getPrintLineWidth() {
188 return _print_line_width;
191 final int getPrintSizeX() {
192 return _print_size_x;
195 final int getPrintSizeY() {
196 return _print_size_y;
199 final double getScaleBarLength() {
200 return _scale_bar_length;
203 final TAXONOMY_EXTRACTION getTaxonomyExtraction() {
204 return _taxonomy_extraction;
207 final boolean isAbbreviateScientificTaxonNames() {
208 return _abbreviate_scientific_names;
211 boolean isAllowMagnificationOfTaxonomyImages() {
215 final boolean isAntialiasPrint() {
216 return _antialias_print;
219 final boolean isAntialiasScreen() {
220 return _antialias_screen;
223 final boolean isBackgroundColorGradient() {
224 return _background_color_gradient;
227 final boolean isColorByTaxonomicGroup() {
228 return _color_by_taxonomic_group;
231 final boolean isColorLabelsSameAsParentBranch() {
232 return _color_labels_same_as_parent_branch;
235 final boolean isEditable() {
239 final boolean isGraphicsExportUsingActualSize() {
240 return _graphics_export_using_actual_size;
243 final boolean isGraphicsExportVisibleOnly() {
244 return _graphics_export_visible_only;
247 final boolean isInternalNumberAreConfidenceForNhParsing() {
248 return _internal_number_are_confidence_for_nh_parsing;
251 final boolean isInverseSearchResult() {
252 return _inverse_search_result;
255 final boolean isMatchWholeTermsOnly() {
256 return _match_whole_terms_only;
259 final boolean isPrintBlackAndWhite() {
260 return _print_black_and_white;
263 final boolean isPrintUsingActualSize() {
264 return _print_using_actual_size;
267 final boolean isReplaceUnderscoresInNhParsing() {
268 return _nh_parsing_replace_underscores;
271 final boolean isSearchCaseSensitive() {
272 return _search_case_sensitive;
275 final boolean isShowBranchLengthValues() {
276 return _show_branch_length_values;
279 boolean isShowConfidenceStddev() {
280 return _show_confidence_stddev;
283 boolean isShowDefaultNodeShapesExternal() {
284 return _show_default_node_shapes_external;
287 boolean isShowDefaultNodeShapesInternal() {
288 return _show_default_node_shapes_internal;
291 final boolean isShowOverview() {
292 return _show_overview;
295 final boolean isShowScale() {
299 final void setAbbreviateScientificTaxonNames( final boolean abbreviate_scientific_names ) {
300 _abbreviate_scientific_names = abbreviate_scientific_names;
303 final void setAntialiasPrint( final boolean antialias_print ) {
304 _antialias_print = antialias_print;
307 final void setAntialiasScreen( final boolean antialias_screen ) {
308 _antialias_screen = antialias_screen;
311 final void setBaseFont( final Font base_font ) {
312 _base_font = base_font;
315 final void setCladogramType( final CLADOGRAM_TYPE cladogram_type ) {
316 _cladogram_type = cladogram_type;
319 final void setColorByTaxonomicGroup( final boolean color_by_taxonomic_group ) {
320 _color_by_taxonomic_group = color_by_taxonomic_group;
323 final void setDefaultNodeFill( final NodeFill default_node_fill ) {
324 _default_node_fill = default_node_fill;
327 final void setDefaultNodeShape( final NodeShape default_node_shape ) {
328 _default_node_shape = default_node_shape;
331 final void setDefaultNodeShapeSize( final short default_node_shape_size ) {
332 _default_node_shape_size = default_node_shape_size;
335 final void setEditable( final boolean editable ) {
336 _editable = editable;
339 final void setGraphicsExportUsingActualSize( final boolean graphics_export_using_actual_size ) {
340 _graphics_export_using_actual_size = graphics_export_using_actual_size;
341 if ( !graphics_export_using_actual_size ) {
342 setGraphicsExportVisibleOnly( false );
346 final void setGraphicsExportVisibleOnly( final boolean graphics_export_visible_only ) {
347 _graphics_export_visible_only = graphics_export_visible_only;
348 if ( graphics_export_visible_only ) {
349 setGraphicsExportUsingActualSize( true );
353 final void setInternalNumberAreConfidenceForNhParsing( final boolean internal_number_are_confidence_for_nh_parsing ) {
354 _internal_number_are_confidence_for_nh_parsing = internal_number_are_confidence_for_nh_parsing;
357 final void setInverseSearchResult( final boolean inverse_search_result ) {
358 _inverse_search_result = inverse_search_result;
361 final void setMatchWholeTermsOnly( final boolean search_whole_words_only ) {
362 _match_whole_terms_only = search_whole_words_only;
365 final void setMinConfidenceValue( final double min_confidence_value ) {
366 _min_confidence_value = min_confidence_value;
369 void setNhConversionSupportValueStyle( final NH_CONVERSION_SUPPORT_VALUE_STYLE nh_conversion_support_value_style ) {
370 _nh_conversion_support_value_style = nh_conversion_support_value_style;
373 final void setNodeLabelDirection( final NODE_LABEL_DIRECTION node_label_direction ) {
374 _node_label_direction = node_label_direction;
377 final void setOvPlacement( final OVERVIEW_PLACEMENT_TYPE ov_placement ) {
378 _ov_placement = ov_placement;
381 final void setPhylogenyGraphicsType( final PHYLOGENY_GRAPHICS_TYPE phylogeny_graphics_type ) {
382 _phylogeny_graphics_type = phylogeny_graphics_type;
385 final void setPrintBlackAndWhite( final boolean print_black_and_white ) {
386 _print_black_and_white = print_black_and_white;
389 final void setPrintLineWidth( final float print_line_width ) {
390 _print_line_width = print_line_width;
393 final void setPrintSizeX( final int print_size_x ) {
394 _print_size_x = print_size_x;
397 final void setPrintSizeY( final int print_size_y ) {
398 _print_size_y = print_size_y;
401 final void setPrintUsingActualSize( final boolean print_using_actual_size ) {
402 _print_using_actual_size = print_using_actual_size;
405 final void setReplaceUnderscoresInNhParsing( final boolean nh_parsing_replace_underscores ) {
406 _nh_parsing_replace_underscores = nh_parsing_replace_underscores;
409 final void setScaleBarLength( final double scale_bar_length ) {
410 _scale_bar_length = scale_bar_length;
413 final void setSearchCaseSensitive( final boolean search_case_sensitive ) {
414 _search_case_sensitive = search_case_sensitive;
417 final void setShowBranchLengthValues( final boolean show_branch_length_values ) {
418 _show_branch_length_values = show_branch_length_values;
421 void setShowConfidenceStddev( final boolean show_confidence_stddev ) {
422 _show_confidence_stddev = show_confidence_stddev;
425 void setShowDefaultNodeShapesExternal( final boolean show_default_node_shapes_external ) {
426 _show_default_node_shapes_external = show_default_node_shapes_external;
429 void setShowDefaultNodeShapesInternal( final boolean show_default_node_shapes_internal ) {
430 _show_default_node_shapes_internal = show_default_node_shapes_internal;
433 final void setShowOverview( final boolean show_overview ) {
434 _show_overview = show_overview;
437 final void setShowScale( final boolean show_scale ) {
438 _show_scale = show_scale;
441 final void setTaxonomyExtraction( final TAXONOMY_EXTRACTION taxonomy_extraction ) {
442 _taxonomy_extraction = taxonomy_extraction;
445 final private void init() {
446 _default_node_shape = NodeShape.CIRCLE;
447 _default_node_fill = NodeFill.GRADIENT;
448 _default_node_shape_size = Constants.DEFAULT_NODE_SHAPE_SIZE_DEFAULT;
449 _show_branch_length_values = false;
450 _internal_number_are_confidence_for_nh_parsing = false;
452 _antialias_screen = true;
453 _antialias_print = true;
454 _graphics_export_visible_only = false;
456 _background_color_gradient = false;
457 _show_default_node_shapes_internal = false;
458 _show_default_node_shapes_external = false;
459 if ( AptxUtil.isUsOrCanada() ) {
460 _print_size_x = Constants.US_LETTER_SIZE_X;
461 _print_size_y = Constants.US_LETTER_SIZE_Y;
464 _print_size_x = Constants.A4_SIZE_X;
465 _print_size_y = Constants.A4_SIZE_Y;
467 _min_confidence_value = MIN_CONFIDENCE_DEFAULT;
468 _print_black_and_white = false;
469 _print_using_actual_size = true;
470 _graphics_export_using_actual_size = true;
471 _phylogeny_graphics_type = PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR;
472 _base_font = new Font( Configuration.getDefaultFontFamilyName(), Font.PLAIN, 10 );
473 _match_whole_terms_only = false;
474 _search_case_sensitive = false;
475 _print_line_width = Constants.PDF_LINE_WIDTH_DEFAULT;
476 _show_overview = true;
477 _ov_placement = OVERVIEW_PLACEMENT_TYPE.UPPER_LEFT;
478 _node_label_direction = NODE_LABEL_DIRECTION.HORIZONTAL;
479 _inverse_search_result = false;
480 _scale_bar_length = 0.0;
481 _number_of_digits_after_comma_for_branch_length_values = Constants.NUMBER_OF_DIGITS_AFTER_COMMA_FOR_BRANCH_LENGTH_VALUES_DEFAULT;
482 _number_of_digits_after_comma_for_confidence_values = Constants.NUMBER_OF_DIGITS_AFTER_COMMA_FOR_CONFIDENCE_VALUES_DEFAULT;
483 _nh_parsing_replace_underscores = false;
484 _taxonomy_extraction = TAXONOMY_EXTRACTION.NO;
485 _cladogram_type = Constants.CLADOGRAM_TYPE_DEFAULT;
486 _show_domain_labels = true;
487 _show_annotation_ref_source = true;
488 setAbbreviateScientificTaxonNames( false );
489 _color_labels_same_as_parent_branch = false;
490 _show_confidence_stddev = true;
491 _nh_conversion_support_value_style = NH_CONVERSION_SUPPORT_VALUE_STYLE.NONE;
492 _ext_desc_data_to_return = NODE_DATA.UNKNOWN;
493 _line_up_renderable_node_data = false;
494 _right_align_domains = false;
497 final private void setNumberOfDigitsAfterCommaForBranchLength( final short number_of_digits_after_comma_for_branch_length_values ) {
498 _number_of_digits_after_comma_for_branch_length_values = number_of_digits_after_comma_for_branch_length_values;
501 final private void setNumberOfDigitsAfterCommaForConfidenceValues( final short number_of_digits_after_comma_for_confidence_values ) {
502 _number_of_digits_after_comma_for_confidence_values = number_of_digits_after_comma_for_confidence_values;
505 public final static Options createInstance( final Configuration configuration ) {
506 final Options instance = createDefaultInstance();
507 if ( configuration != null ) {
508 instance.setAntialiasScreen( configuration.isAntialiasScreen() );
509 instance.setShowScale( configuration.isShowScale() );
510 instance.setShowBranchLengthValues( configuration.isShowBranchLengthValues() );
511 instance.setShowOverview( configuration.isShowOverview() );
512 instance.setColorByTaxonomicGroup( configuration.isColorByTaxonomicGroup() );
513 instance.setCladogramType( configuration.getCladogramType() );
514 instance.setOvPlacement( configuration.getOvPlacement() );
515 instance.setPrintLineWidth( configuration.getPrintLineWidth() );
516 instance.setNodeLabelDirection( configuration.getNodeLabelDirection() );
517 instance.setBackgroundColorGradient( configuration.isBackgroundColorGradient() );
518 if ( configuration.getNumberOfDigitsAfterCommaForBranchLengthValues() >= 0 ) {
519 instance.setNumberOfDigitsAfterCommaForBranchLength( configuration
520 .getNumberOfDigitsAfterCommaForBranchLengthValues() );
522 if ( configuration.getNumberOfDigitsAfterCommaForConfidenceValues() >= 0 ) {
523 instance.setNumberOfDigitsAfterCommaForConfidenceValues( configuration
524 .getNumberOfDigitsAfterCommaForConfidenceValues() );
526 instance.setTaxonomyExtraction( configuration.getTaxonomyExtraction() );
527 instance.setReplaceUnderscoresInNhParsing( configuration.isReplaceUnderscoresInNhParsing() );
528 instance.setInternalNumberAreConfidenceForNhParsing( configuration
529 .isInternalNumberAreConfidenceForNhParsing() );
530 instance.setEditable( configuration.isEditable() );
531 instance.setColorLabelsSameAsParentBranch( configuration.isColorLabelsSameAsParentBranch() );
532 instance.setShowDomainLabels( configuration.isShowDomainLabels() );
533 instance.setShowAnnotationRefSource( configuration.isShowAnnotationRefSource() );
534 instance.setAbbreviateScientificTaxonNames( configuration.isAbbreviateScientificTaxonNames() );
535 if ( configuration.getMinConfidenceValue() != MIN_CONFIDENCE_DEFAULT ) {
536 instance.setMinConfidenceValue( configuration.getMinConfidenceValue() );
538 if ( configuration.getGraphicsExportX() > 0 ) {
539 instance.setPrintSizeX( configuration.getGraphicsExportX() );
541 if ( configuration.getGraphicsExportY() > 0 ) {
542 instance.setPrintSizeY( configuration.getGraphicsExportY() );
544 if ( configuration.getBaseFontSize() > 0 ) {
545 instance.setBaseFont( instance.getBaseFont().deriveFont( ( float ) configuration.getBaseFontSize() ) );
547 if ( !ForesterUtil.isEmpty( configuration.getBaseFontFamilyName() ) ) {
548 instance.setBaseFont( new Font( configuration.getBaseFontFamilyName(), Font.PLAIN, instance
549 .getBaseFont().getSize() ) );
551 if ( configuration.getPhylogenyGraphicsType() != null ) {
552 instance.setPhylogenyGraphicsType( configuration.getPhylogenyGraphicsType() );
554 if ( configuration.getDefaultNodeFill() != null ) {
555 instance.setDefaultNodeFill( configuration.getDefaultNodeFill() );
557 if ( configuration.getDefaultNodeShape() != null ) {
558 instance.setDefaultNodeShape( configuration.getDefaultNodeShape() );
560 if ( configuration.getDefaultNodeShapeSize() >= 0 ) {
561 instance.setDefaultNodeShapeSize( configuration.getDefaultNodeShapeSize() );
563 instance.setShowDefaultNodeShapesInternal( configuration.isShowDefaultNodeShapesInternal() );
564 instance.setShowDefaultNodeShapesExternal( configuration.isShowDefaultNodeShapesExternal() );
565 if ( configuration.getExtDescNodeDataToReturn() != null ) {
566 instance.setExtDescNodeDataToReturn( configuration.getExtDescNodeDataToReturn() );
568 instance.setRightLineUpDomains( configuration.isRightLineUpDomains() );
569 instance.setLineUpRendarableNodeData( configuration.isLineUpRendarableNodeData() );
570 instance.setAllowErrorsInDistanceToParent( false );
575 final static Options createDefaultInstance() {
576 return new Options();
579 public static enum CLADOGRAM_TYPE {
580 EXT_NODE_SUM_DEP, NON_LINED_UP, TOTAL_NODE_SUM_DEP;
583 public static enum NODE_LABEL_DIRECTION {
587 public static enum PHYLOGENY_GRAPHICS_TYPE {
588 CIRCULAR, CONVEX, CURVED, EURO_STYLE, RECTANGULAR, ROUNDED, TRIANGULAR, UNROOTED;
591 static enum OVERVIEW_PLACEMENT_TYPE {
592 LOWER_LEFT( "lower left" ),
593 LOWER_RIGHT( "lower right" ),
594 UPPER_LEFT( "upper left" ),
595 UPPER_RIGHT( "upper right" );
597 private final String _name;
599 private OVERVIEW_PLACEMENT_TYPE( final String name ) {
604 public String toString() {
608 public String toTag() {
609 return toString().replaceAll( " ", "_" );
613 final public boolean isLineUpRendarableNodeData() {
614 return _line_up_renderable_node_data;
617 final public boolean isRightLineUpDomains() {
618 return _right_align_domains;
621 final public void setLineUpRendarableNodeData( final boolean line_up_renderable_node_data ) {
622 _line_up_renderable_node_data = line_up_renderable_node_data;
625 final public void setRightLineUpDomains( final boolean right_align_domains ) {
626 _right_align_domains = right_align_domains;