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.NodeDataField;
33 import org.forester.phylogeny.data.NodeVisualData;
34 import org.forester.phylogeny.data.NodeVisualData.NodeFill;
35 import org.forester.phylogeny.data.NodeVisualData.NodeShape;
36 import org.forester.util.ForesterUtil;
39 * This is to hold changeable options.
41 final public class Options {
43 public static enum CLADOGRAM_TYPE {
44 LINED_UP, NON_LINED_UP;
47 public static enum NODE_LABEL_DIRECTION {
51 public static enum PHYLOGENY_GRAPHICS_TYPE {
52 CIRCULAR, CONVEX, CURVED, EURO_STYLE, RECTANGULAR, ROUNDED, TRIANGULAR, UNROOTED;
55 static enum PHYLOGENY_DISPLAY_TYPE {
61 static enum OVERVIEW_PLACEMENT_TYPE {
62 LOWER_LEFT( "lower left" ),
63 LOWER_RIGHT( "lower right" ),
64 UPPER_LEFT( "upper left" ),
65 UPPER_RIGHT( "upper right" );
67 private final String _name;
69 private OVERVIEW_PLACEMENT_TYPE( final String name ) {
74 public String toString() {
78 public String toTag() {
79 return toString().replaceAll( " ", "_" );
83 static final double MIN_CONFIDENCE_DEFAULT = 0.0;
84 private boolean _abbreviate_scientific_names;
85 private boolean _allow_errors_in_distance_to_parent;
86 private boolean _antialias_print;
87 private boolean _antialias_screen;
88 private boolean _background_color_gradient;
89 private Font _base_font;
90 private CLADOGRAM_TYPE _cladogram_type;
91 private boolean _color_by_taxonomic_group;
92 private boolean _color_labels_same_as_parent_branch;
93 private NodeVisualData.NodeFill _default_node_fill;
94 private NodeVisualData.NodeShape _default_node_shape;
95 private short _default_node_shape_size;
96 private boolean _editable;
97 private NodeDataField _ext_desc_data_to_return;
98 private final boolean _graphics_export_using_actual_size = true;
99 private boolean _graphics_export_visible_only;
100 private boolean _internal_number_are_confidence_for_nh_parsing;
101 private boolean _inverse_search_result;
102 private boolean _match_whole_terms_only;
103 private boolean _search_with_regex;
104 private double _min_confidence_value;
105 private NH_CONVERSION_SUPPORT_VALUE_STYLE _nh_conversion_support_value_style;
106 private boolean _nh_parsing_replace_underscores;
107 private NODE_LABEL_DIRECTION _node_label_direction;
108 private short _number_of_digits_after_comma_for_branch_length_values;
109 private short _number_of_digits_after_comma_for_confidence_values;
110 private OVERVIEW_PLACEMENT_TYPE _ov_placement;
111 private PHYLOGENY_GRAPHICS_TYPE _phylogeny_graphics_type;
112 private boolean _print_black_and_white;
113 private float _print_line_width;
114 private final boolean _print_using_actual_size = true;
115 private double _scale_bar_length;
116 private boolean _search_case_sensitive;
117 private boolean _show_annotation_ref_source;
118 private boolean _show_confidence_stddev;
119 private boolean _show_default_node_shapes_for_marked_nodes;
120 private boolean _show_default_node_shapes_external;
121 private boolean _show_default_node_shapes_internal;
122 private boolean _show_domain_labels;
123 private boolean _show_overview;
124 private boolean _show_scale;
125 private TAXONOMY_EXTRACTION _taxonomy_extraction;
126 private boolean _line_up_renderable_node_data;
127 private boolean _right_align_domains;
128 private boolean _color_all_found_nodes_when_coloring_subtree;
129 private boolean _parse_beast_style_extended_nexus_tags;
130 private boolean _collapsed_with_average_height;
131 private boolean _show_abbreviated_labels_for_collapsed_nodes;
137 public NodeDataField getExtDescNodeDataToReturn() {
138 return _ext_desc_data_to_return;
141 public boolean isAllowErrorsInDistanceToParent() {
142 return _allow_errors_in_distance_to_parent;
145 final public boolean isLineUpRendarableNodeData() {
146 return _line_up_renderable_node_data;
149 final public boolean isRightLineUpDomains() {
150 return _right_align_domains;
153 public final boolean isShowAnnotationRefSource() {
154 return _show_annotation_ref_source;
157 public final boolean isShowDomainLabels() {
158 return _show_domain_labels;
161 public final void setAllowErrorsInDistanceToParent( final boolean allow_errors_in_distance_to_parent ) {
162 _allow_errors_in_distance_to_parent = allow_errors_in_distance_to_parent;
165 public void setBackgroundColorGradient( final boolean background_color_gradient ) {
166 _background_color_gradient = background_color_gradient;
169 public void setColorLabelsSameAsParentBranch( final boolean color_labels_same_as_parent_branch ) {
170 _color_labels_same_as_parent_branch = color_labels_same_as_parent_branch;
173 public void setExtDescNodeDataToReturn( final NodeDataField ext_desc_data_to_return ) {
174 _ext_desc_data_to_return = ext_desc_data_to_return;
177 final public void setLineUpRendarableNodeData( final boolean line_up_renderable_node_data ) {
178 _line_up_renderable_node_data = line_up_renderable_node_data;
181 final public void setRightLineUpDomains( final boolean right_align_domains ) {
182 _right_align_domains = right_align_domains;
185 public final void setShowAnnotationRefSource( final boolean show_annotation_ref_source ) {
186 _show_annotation_ref_source = show_annotation_ref_source;
189 public void setShowDomainLabels( final boolean show_domain_labels ) {
190 _show_domain_labels = show_domain_labels;
193 final private void init() {
194 _default_node_shape = NodeShape.CIRCLE;
195 _default_node_fill = NodeFill.GRADIENT;
196 _default_node_shape_size = AptxConstants.DEFAULT_NODE_SHAPE_SIZE_DEFAULT;
197 _internal_number_are_confidence_for_nh_parsing = false;
199 _antialias_screen = true;
200 _antialias_print = true;
201 _graphics_export_visible_only = false;
203 _background_color_gradient = false;
204 _show_default_node_shapes_internal = false;
205 _show_default_node_shapes_external = false;
206 _show_default_node_shapes_for_marked_nodes = false;
207 _color_all_found_nodes_when_coloring_subtree = false;
208 _parse_beast_style_extended_nexus_tags= true;
209 _min_confidence_value = MIN_CONFIDENCE_DEFAULT;
210 _print_black_and_white = false;
211 _phylogeny_graphics_type = PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR;
212 _base_font = new Font( Configuration.getDefaultFontFamilyName(), Font.PLAIN, 10 );
213 _match_whole_terms_only = false;
214 _search_with_regex = false;
215 _search_case_sensitive = false;
216 _print_line_width = AptxConstants.PDF_LINE_WIDTH_DEFAULT;
217 _show_overview = true;
218 _ov_placement = OVERVIEW_PLACEMENT_TYPE.UPPER_LEFT;
219 _node_label_direction = NODE_LABEL_DIRECTION.HORIZONTAL;
220 _inverse_search_result = false;
221 _scale_bar_length = 0.0;
222 _number_of_digits_after_comma_for_branch_length_values = AptxConstants.NUMBER_OF_DIGITS_AFTER_COMMA_FOR_BRANCH_LENGTH_VALUES_DEFAULT;
223 _number_of_digits_after_comma_for_confidence_values = AptxConstants.NUMBER_OF_DIGITS_AFTER_COMMA_FOR_CONFIDENCE_VALUES_DEFAULT;
224 _nh_parsing_replace_underscores = false;
225 _taxonomy_extraction = TAXONOMY_EXTRACTION.NO;
226 _cladogram_type = AptxConstants.CLADOGRAM_TYPE_DEFAULT;
227 _show_domain_labels = true;
228 _show_annotation_ref_source = true;
229 setAbbreviateScientificTaxonNames( false );
230 _color_labels_same_as_parent_branch = false;
231 _show_confidence_stddev = false;
232 _nh_conversion_support_value_style = NH_CONVERSION_SUPPORT_VALUE_STYLE.NONE;
233 _ext_desc_data_to_return = NodeDataField.UNKNOWN;
234 _line_up_renderable_node_data = true;
235 _right_align_domains = false;
236 _collapsed_with_average_height = true;
237 _show_abbreviated_labels_for_collapsed_nodes = true;
240 final private void setNumberOfDigitsAfterCommaForBranchLength( final short number_of_digits_after_comma_for_branch_length_values ) {
241 _number_of_digits_after_comma_for_branch_length_values = number_of_digits_after_comma_for_branch_length_values;
244 final private void setNumberOfDigitsAfterCommaForConfidenceValues( final short number_of_digits_after_comma_for_confidence_values ) {
245 _number_of_digits_after_comma_for_confidence_values = number_of_digits_after_comma_for_confidence_values;
248 final Font getBaseFont() {
252 final CLADOGRAM_TYPE getCladogramType() {
253 return _cladogram_type;
256 final NodeFill getDefaultNodeFill() {
257 return _default_node_fill;
260 final NodeShape getDefaultNodeShape() {
261 return _default_node_shape;
264 final short getDefaultNodeShapeSize() {
265 return _default_node_shape_size;
268 final double getMinConfidenceValue() {
269 return _min_confidence_value;
272 NH_CONVERSION_SUPPORT_VALUE_STYLE getNhConversionSupportValueStyle() {
273 return _nh_conversion_support_value_style;
276 final NODE_LABEL_DIRECTION getNodeLabelDirection() {
277 return _node_label_direction;
280 final short getNumberOfDigitsAfterCommaForBranchLengthValues() {
281 return _number_of_digits_after_comma_for_branch_length_values;
284 final short getNumberOfDigitsAfterCommaForConfidenceValues() {
285 return _number_of_digits_after_comma_for_confidence_values;
288 final OVERVIEW_PLACEMENT_TYPE getOvPlacement() {
289 return _ov_placement;
292 final PHYLOGENY_GRAPHICS_TYPE getPhylogenyGraphicsType() {
293 return _phylogeny_graphics_type;
296 final float getPrintLineWidth() {
297 return _print_line_width;
300 final double getScaleBarLength() {
301 return _scale_bar_length;
304 final TAXONOMY_EXTRACTION getTaxonomyExtraction() {
305 return _taxonomy_extraction;
308 final boolean isAbbreviateScientificTaxonNames() {
309 return _abbreviate_scientific_names;
312 boolean isAllowMagnificationOfTaxonomyImages() {
316 final boolean isAntialiasPrint() {
317 return _antialias_print;
320 final boolean isAntialiasScreen() {
321 return _antialias_screen;
324 final boolean isBackgroundColorGradient() {
325 return _background_color_gradient;
328 final boolean isColorByTaxonomicGroup() {
329 return _color_by_taxonomic_group;
332 final boolean isColorLabelsSameAsParentBranch() {
333 return _color_labels_same_as_parent_branch;
336 final boolean isEditable() {
340 final boolean isGraphicsExportUsingActualSize() {
341 return _graphics_export_using_actual_size;
344 final boolean isGraphicsExportVisibleOnly() {
345 return _graphics_export_visible_only;
348 final boolean isInternalNumberAreConfidenceForNhParsing() {
349 return _internal_number_are_confidence_for_nh_parsing;
352 final boolean isInverseSearchResult() {
353 return _inverse_search_result;
356 final boolean isMatchWholeTermsOnly() {
357 return _match_whole_terms_only;
360 final boolean isPrintBlackAndWhite() {
361 return _print_black_and_white;
364 final boolean isPrintUsingActualSize() {
365 return _print_using_actual_size;
368 final boolean isReplaceUnderscoresInNhParsing() {
369 return _nh_parsing_replace_underscores;
372 final boolean isSearchCaseSensitive() {
373 return _search_case_sensitive;
376 final boolean isSearchWithRegex() {
377 return _search_with_regex;
380 boolean isShowConfidenceStddev() {
381 return _show_confidence_stddev;
384 boolean isShowDefaultNodeShapesExternal() {
385 return _show_default_node_shapes_external;
388 boolean isShowDefaultNodeShapesForMarkedNodes() {
389 return _show_default_node_shapes_for_marked_nodes;
392 boolean isShowDefaultNodeShapesInternal() {
393 return _show_default_node_shapes_internal;
396 final boolean isShowOverview() {
397 return _show_overview;
400 final boolean isShowScale() {
404 final void setAbbreviateScientificTaxonNames( final boolean abbreviate_scientific_names ) {
405 _abbreviate_scientific_names = abbreviate_scientific_names;
408 final void setAntialiasPrint( final boolean antialias_print ) {
409 _antialias_print = antialias_print;
412 final void setAntialiasScreen( final boolean antialias_screen ) {
413 _antialias_screen = antialias_screen;
416 final void setBaseFont( final Font base_font ) {
417 _base_font = base_font;
420 final void setCladogramType( final CLADOGRAM_TYPE cladogram_type ) {
421 _cladogram_type = cladogram_type;
424 final void setColorByTaxonomicGroup( final boolean color_by_taxonomic_group ) {
425 _color_by_taxonomic_group = color_by_taxonomic_group;
428 final void setDefaultNodeFill( final NodeFill default_node_fill ) {
429 _default_node_fill = default_node_fill;
432 final void setDefaultNodeShape( final NodeShape default_node_shape ) {
433 _default_node_shape = default_node_shape;
436 final void setDefaultNodeShapeSize( final short default_node_shape_size ) {
437 _default_node_shape_size = default_node_shape_size;
440 final void setEditable( final boolean editable ) {
441 _editable = editable;
444 final void setGraphicsExportVisibleOnly( final boolean graphics_export_visible_only ) {
445 _graphics_export_visible_only = graphics_export_visible_only;
448 final void setInternalNumberAreConfidenceForNhParsing( final boolean internal_number_are_confidence_for_nh_parsing ) {
449 _internal_number_are_confidence_for_nh_parsing = internal_number_are_confidence_for_nh_parsing;
452 final void setInverseSearchResult( final boolean inverse_search_result ) {
453 _inverse_search_result = inverse_search_result;
456 final void setMatchWholeTermsOnly( final boolean search_whole_words_only ) {
457 _match_whole_terms_only = search_whole_words_only;
460 final void setMinConfidenceValue( final double min_confidence_value ) {
461 _min_confidence_value = min_confidence_value;
464 void setNhConversionSupportValueStyle( final NH_CONVERSION_SUPPORT_VALUE_STYLE nh_conversion_support_value_style ) {
465 _nh_conversion_support_value_style = nh_conversion_support_value_style;
468 final void setNodeLabelDirection( final NODE_LABEL_DIRECTION node_label_direction ) {
469 _node_label_direction = node_label_direction;
472 final void setOvPlacement( final OVERVIEW_PLACEMENT_TYPE ov_placement ) {
473 _ov_placement = ov_placement;
476 final void setPhylogenyGraphicsType( final PHYLOGENY_GRAPHICS_TYPE phylogeny_graphics_type ) {
477 _phylogeny_graphics_type = phylogeny_graphics_type;
480 final void setPrintBlackAndWhite( final boolean print_black_and_white ) {
481 _print_black_and_white = print_black_and_white;
484 final void setPrintLineWidth( final float print_line_width ) {
485 _print_line_width = print_line_width;
488 final void setReplaceUnderscoresInNhParsing( final boolean nh_parsing_replace_underscores ) {
489 _nh_parsing_replace_underscores = nh_parsing_replace_underscores;
492 final void setScaleBarLength( final double scale_bar_length ) {
493 _scale_bar_length = scale_bar_length;
496 final void setSearchCaseSensitive( final boolean search_case_sensitive ) {
497 _search_case_sensitive = search_case_sensitive;
500 final void setSearchWithRegex( final boolean search_with_regex ) {
501 _search_with_regex = search_with_regex;
504 void setShowConfidenceStddev( final boolean show_confidence_stddev ) {
505 _show_confidence_stddev = show_confidence_stddev;
508 void setShowDefaultNodeShapesExternal( final boolean show_default_node_shapes_external ) {
509 _show_default_node_shapes_external = show_default_node_shapes_external;
512 void setShowDefaultNodeShapesForMarkedNodes( final boolean show_default_node_shapes_for_marked_nodes ) {
513 _show_default_node_shapes_for_marked_nodes = show_default_node_shapes_for_marked_nodes;
516 void setShowDefaultNodeShapesInternal( final boolean show_default_node_shapes_internal ) {
517 _show_default_node_shapes_internal = show_default_node_shapes_internal;
520 final void setShowOverview( final boolean show_overview ) {
521 _show_overview = show_overview;
524 final void setShowScale( final boolean show_scale ) {
525 _show_scale = show_scale;
528 final void setTaxonomyExtraction( final TAXONOMY_EXTRACTION taxonomy_extraction ) {
529 _taxonomy_extraction = taxonomy_extraction;
532 public final static Options createInstance( final Configuration configuration ) {
533 final Options instance = createDefaultInstance();
534 if ( configuration != null ) {
535 instance.setAntialiasScreen( configuration.isAntialiasScreen() );
536 instance.setShowScale( configuration.isShowScale() );
537 instance.setShowOverview( configuration.isShowOverview() );
538 instance.setColorByTaxonomicGroup( configuration.isColorByTaxonomicGroup() );
539 instance.setCladogramType( configuration.getCladogramType() );
540 instance.setOvPlacement( configuration.getOvPlacement() );
541 instance.setPrintLineWidth( configuration.getPrintLineWidth() );
542 instance.setNodeLabelDirection( configuration.getNodeLabelDirection() );
543 instance.setBackgroundColorGradient( configuration.isBackgroundColorGradient() );
544 if ( configuration.getNumberOfDigitsAfterCommaForBranchLengthValues() >= 0 ) {
545 instance.setNumberOfDigitsAfterCommaForBranchLength( configuration
546 .getNumberOfDigitsAfterCommaForBranchLengthValues() );
548 if ( configuration.getNumberOfDigitsAfterCommaForConfidenceValues() >= 0 ) {
549 instance.setNumberOfDigitsAfterCommaForConfidenceValues( configuration
550 .getNumberOfDigitsAfterCommaForConfidenceValues() );
552 instance.setTaxonomyExtraction( configuration.getTaxonomyExtraction() );
553 instance.setReplaceUnderscoresInNhParsing( configuration.isReplaceUnderscoresInNhParsing() );
554 instance.setInternalNumberAreConfidenceForNhParsing( configuration
555 .isInternalNumberAreConfidenceForNhParsing() );
556 instance.setEditable( configuration.isEditable() );
557 instance.setColorLabelsSameAsParentBranch( configuration.isColorLabelsSameAsParentBranch() );
558 instance.setShowDomainLabels( configuration.isShowDomainLabels() );
559 instance.setShowAnnotationRefSource( configuration.isShowAnnotationRefSource() );
560 instance.setAbbreviateScientificTaxonNames( configuration.isAbbreviateScientificTaxonNames() );
561 if ( configuration.getMinConfidenceValue() != MIN_CONFIDENCE_DEFAULT ) {
562 instance.setMinConfidenceValue( configuration.getMinConfidenceValue() );
564 if ( configuration.getBaseFontSize() > 0 ) {
565 instance.setBaseFont( instance.getBaseFont().deriveFont( ( float ) configuration.getBaseFontSize() ) );
567 if ( !ForesterUtil.isEmpty( configuration.getBaseFontFamilyName() ) ) {
568 instance.setBaseFont( new Font( configuration.getBaseFontFamilyName(), Font.PLAIN, instance
569 .getBaseFont().getSize() ) );
571 if ( configuration.getPhylogenyGraphicsType() != null ) {
572 instance.setPhylogenyGraphicsType( configuration.getPhylogenyGraphicsType() );
574 if ( configuration.getDefaultNodeFill() != null ) {
575 instance.setDefaultNodeFill( configuration.getDefaultNodeFill() );
577 if ( configuration.getDefaultNodeShape() != null ) {
578 instance.setDefaultNodeShape( configuration.getDefaultNodeShape() );
580 if ( configuration.getDefaultNodeShapeSize() >= 0 ) {
581 instance.setDefaultNodeShapeSize( configuration.getDefaultNodeShapeSize() );
583 instance.setShowDefaultNodeShapesInternal( configuration.isShowDefaultNodeShapesInternal() );
584 instance.setShowDefaultNodeShapesExternal( configuration.isShowDefaultNodeShapesExternal() );
585 instance.setShowDefaultNodeShapesForMarkedNodes( configuration.isShowDefaultNodeShapesForMarkedNodes() );
586 if ( configuration.getExtDescNodeDataToReturn() != null ) {
587 instance.setExtDescNodeDataToReturn( configuration.getExtDescNodeDataToReturn() );
589 instance.setRightLineUpDomains( configuration.isRightLineUpDomains() );
590 instance.setLineUpRendarableNodeData( configuration.isLineUpRendarableNodeData() );
591 instance.setAllowErrorsInDistanceToParent( false );
596 final static Options createDefaultInstance() {
597 return new Options();
600 final boolean isColorAllFoundNodesWhenColoringSubtree() {
601 return _color_all_found_nodes_when_coloring_subtree;
604 final void setColorAllFoundNodesWhenColoringSubtree( final boolean color_all_found_nodes_when_coloring_subtree ) {
605 _color_all_found_nodes_when_coloring_subtree = color_all_found_nodes_when_coloring_subtree;
608 final boolean isParseBeastStyleExtendedNexusTags() {
609 return _parse_beast_style_extended_nexus_tags;
612 final void setParseBeastStyleExtendedNexusTags( final boolean parse_beast_style_extended_nexus_tags ) {
613 _parse_beast_style_extended_nexus_tags = parse_beast_style_extended_nexus_tags;
616 final boolean isCollapsedWithAverageHeigh() {
617 return _collapsed_with_average_height;
620 final void setCollapsedWithAverageHeigh( final boolean collapsed_with_average_height ) {
621 _collapsed_with_average_height = collapsed_with_average_height;
624 final boolean isShowAbbreviatedLabelsForCollapsedNodes() {
625 return _show_abbreviated_labels_for_collapsed_nodes;
628 final void setShowAbbreviatedLabelsForCollapsedNodes(final boolean show_abbreviated_labels_for_collapsed_nodes) {
629 _show_abbreviated_labels_for_collapsed_nodes = show_abbreviated_labels_for_collapsed_nodes;