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.NodeVisualization;
35 import org.forester.phylogeny.data.NodeVisualization.NodeFill;
36 import org.forester.phylogeny.data.NodeVisualization.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 _show_branch_length_values;
46 private boolean _internal_number_are_confidence_for_nh_parsing;
47 private boolean _show_scale;
48 private boolean _show_overview;
49 private boolean _antialias_screen;
50 private boolean _antialias_print;
51 private boolean _graphics_export_visible_only;
52 private int _print_size_x;
53 private int _print_size_y;
54 private double _min_confidence_value;
55 private boolean _print_black_and_white;
56 private boolean _print_using_actual_size;
57 private boolean _graphics_export_using_actual_size;
58 private PHYLOGENY_GRAPHICS_TYPE _phylogeny_graphics_type;
59 private CLADOGRAM_TYPE _cladogram_type;
60 private OVERVIEW_PLACEMENT_TYPE _ov_placement;
61 private NODE_LABEL_DIRECTION _node_label_direction;
62 private Font _base_font;
63 private boolean _match_whole_terms_only;
64 private boolean _search_case_sensitive;
65 private float _print_line_width;
66 private boolean _inverse_search_result;
67 private double _scale_bar_length;
68 private short _number_of_digits_after_comma_for_confidence_values;
69 private short _number_of_digits_after_comma_for_branch_length_values;
70 private boolean _nh_parsing_replace_underscores;
71 private TAXONOMY_EXTRACTION _taxonomy_extraction;
72 private boolean _editable;
73 private boolean _background_color_gradient;
74 private boolean _show_domain_labels;
75 private boolean _show_annotation_ref_source;
76 private boolean _color_labels_same_as_parent_branch;
77 private boolean _abbreviate_scientific_names;
78 private NodeVisualization.NodeShape _default_node_shape;
79 private NodeVisualization.NodeFill _default_node_fill;
80 private short _default_node_shape_size;
81 private boolean _taxonomy_colorize_node_shapes;
82 private boolean _show_default_node_shapes_internal;
83 private boolean _show_default_node_shapes_external;
84 private boolean _show_confidence_stddev;
85 private NH_CONVERSION_SUPPORT_VALUE_STYLE _nh_conversion_support_value_style;
86 private NODE_DATA _ext_desc_data_to_return;
92 public NodeData.NODE_DATA getExtDescNodeDataToReturn() {
93 return _ext_desc_data_to_return;
96 public final boolean isShowDomainLabels() {
97 return _show_domain_labels;
100 public final boolean isShowAnnotationRefSource() {
101 return _show_annotation_ref_source;
104 public final void setShowAnnotationRefSource( final boolean show_annotation_ref_source ) {
105 _show_annotation_ref_source = show_annotation_ref_source;
108 public void setBackgroundColorGradient( final boolean background_color_gradient ) {
109 _background_color_gradient = background_color_gradient;
112 public void setColorLabelsSameAsParentBranch( final boolean color_labels_same_as_parent_branch ) {
113 _color_labels_same_as_parent_branch = color_labels_same_as_parent_branch;
116 public void setExtDescNodeDataToReturn( final NODE_DATA ext_desc_data_to_return ) {
117 _ext_desc_data_to_return = ext_desc_data_to_return;
120 public void setShowDomainLabels( final boolean show_domain_labels ) {
121 _show_domain_labels = show_domain_labels;
124 final Font getBaseFont() {
128 final CLADOGRAM_TYPE getCladogramType() {
129 return _cladogram_type;
132 final NodeFill getDefaultNodeFill() {
133 return _default_node_fill;
136 final NodeShape getDefaultNodeShape() {
137 return _default_node_shape;
140 final short getDefaultNodeShapeSize() {
141 return _default_node_shape_size;
144 final double getMinConfidenceValue() {
145 return _min_confidence_value;
148 NH_CONVERSION_SUPPORT_VALUE_STYLE getNhConversionSupportValueStyle() {
149 return _nh_conversion_support_value_style;
152 final NODE_LABEL_DIRECTION getNodeLabelDirection() {
153 return _node_label_direction;
156 final short getNumberOfDigitsAfterCommaForBranchLengthValues() {
157 return _number_of_digits_after_comma_for_branch_length_values;
160 final short getNumberOfDigitsAfterCommaForConfidenceValues() {
161 return _number_of_digits_after_comma_for_confidence_values;
164 final OVERVIEW_PLACEMENT_TYPE getOvPlacement() {
165 return _ov_placement;
168 final PHYLOGENY_GRAPHICS_TYPE getPhylogenyGraphicsType() {
169 return _phylogeny_graphics_type;
172 final float getPrintLineWidth() {
173 return _print_line_width;
176 final int getPrintSizeX() {
177 return _print_size_x;
180 final int getPrintSizeY() {
181 return _print_size_y;
184 final double getScaleBarLength() {
185 return _scale_bar_length;
188 final TAXONOMY_EXTRACTION getTaxonomyExtraction() {
189 return _taxonomy_extraction;
192 final boolean isAbbreviateScientificTaxonNames() {
193 return _abbreviate_scientific_names;
196 boolean isAllowMagnificationOfTaxonomyImages() {
200 final boolean isAntialiasPrint() {
201 return _antialias_print;
204 final boolean isAntialiasScreen() {
205 return _antialias_screen;
208 final boolean isBackgroundColorGradient() {
209 return _background_color_gradient;
212 final boolean isColorLabelsSameAsParentBranch() {
213 return _color_labels_same_as_parent_branch;
216 final boolean isEditable() {
220 final boolean isGraphicsExportUsingActualSize() {
221 return _graphics_export_using_actual_size;
224 final boolean isGraphicsExportVisibleOnly() {
225 return _graphics_export_visible_only;
228 final boolean isInternalNumberAreConfidenceForNhParsing() {
229 return _internal_number_are_confidence_for_nh_parsing;
232 final boolean isInverseSearchResult() {
233 return _inverse_search_result;
236 final boolean isMatchWholeTermsOnly() {
237 return _match_whole_terms_only;
240 final boolean isPrintBlackAndWhite() {
241 return _print_black_and_white;
244 final boolean isPrintUsingActualSize() {
245 return _print_using_actual_size;
248 final boolean isReplaceUnderscoresInNhParsing() {
249 return _nh_parsing_replace_underscores;
252 final boolean isSearchCaseSensitive() {
253 return _search_case_sensitive;
256 final boolean isShowBranchLengthValues() {
257 return _show_branch_length_values;
260 boolean isShowConfidenceStddev() {
261 return _show_confidence_stddev;
264 boolean isShowDefaultNodeShapesExternal() {
265 return _show_default_node_shapes_external;
268 boolean isShowDefaultNodeShapesInternal() {
269 return _show_default_node_shapes_internal;
272 final boolean isShowOverview() {
273 return _show_overview;
276 final boolean isShowScale() {
280 boolean isTaxonomyColorizeNodeShapes() {
281 return _taxonomy_colorize_node_shapes;
284 final void setAbbreviateScientificTaxonNames( final boolean abbreviate_scientific_names ) {
285 _abbreviate_scientific_names = abbreviate_scientific_names;
288 final void setAntialiasPrint( final boolean antialias_print ) {
289 _antialias_print = antialias_print;
292 final void setAntialiasScreen( final boolean antialias_screen ) {
293 _antialias_screen = antialias_screen;
296 final void setBaseFont( final Font base_font ) {
297 _base_font = base_font;
300 final void setCladogramType( final CLADOGRAM_TYPE cladogram_type ) {
301 _cladogram_type = cladogram_type;
304 final void setDefaultNodeFill( final NodeFill default_node_fill ) {
305 _default_node_fill = default_node_fill;
308 final void setDefaultNodeShape( final NodeShape default_node_shape ) {
309 _default_node_shape = default_node_shape;
312 final void setDefaultNodeShapeSize( final short default_node_shape_size ) {
313 _default_node_shape_size = default_node_shape_size;
316 final void setEditable( final boolean editable ) {
317 _editable = editable;
320 final void setGraphicsExportUsingActualSize( final boolean graphics_export_using_actual_size ) {
321 _graphics_export_using_actual_size = graphics_export_using_actual_size;
322 if ( !graphics_export_using_actual_size ) {
323 setGraphicsExportVisibleOnly( false );
327 final void setGraphicsExportVisibleOnly( final boolean graphics_export_visible_only ) {
328 _graphics_export_visible_only = graphics_export_visible_only;
329 if ( graphics_export_visible_only ) {
330 setGraphicsExportUsingActualSize( true );
334 final void setInternalNumberAreConfidenceForNhParsing( final boolean internal_number_are_confidence_for_nh_parsing ) {
335 _internal_number_are_confidence_for_nh_parsing = internal_number_are_confidence_for_nh_parsing;
338 final void setInverseSearchResult( final boolean inverse_search_result ) {
339 _inverse_search_result = inverse_search_result;
342 final void setMatchWholeTermsOnly( final boolean search_whole_words_only ) {
343 _match_whole_terms_only = search_whole_words_only;
346 final void setMinConfidenceValue( final double min_confidence_value ) {
347 _min_confidence_value = min_confidence_value;
350 void setNhConversionSupportValueStyle( final NH_CONVERSION_SUPPORT_VALUE_STYLE nh_conversion_support_value_style ) {
351 _nh_conversion_support_value_style = nh_conversion_support_value_style;
354 final void setNodeLabelDirection( final NODE_LABEL_DIRECTION node_label_direction ) {
355 _node_label_direction = node_label_direction;
358 final void setOvPlacement( final OVERVIEW_PLACEMENT_TYPE ov_placement ) {
359 _ov_placement = ov_placement;
362 final void setPhylogenyGraphicsType( final PHYLOGENY_GRAPHICS_TYPE phylogeny_graphics_type ) {
363 _phylogeny_graphics_type = phylogeny_graphics_type;
366 final void setPrintBlackAndWhite( final boolean print_black_and_white ) {
367 _print_black_and_white = print_black_and_white;
370 final void setPrintLineWidth( final float print_line_width ) {
371 _print_line_width = print_line_width;
374 final void setPrintSizeX( final int print_size_x ) {
375 _print_size_x = print_size_x;
378 final void setPrintSizeY( final int print_size_y ) {
379 _print_size_y = print_size_y;
382 final void setPrintUsingActualSize( final boolean print_using_actual_size ) {
383 _print_using_actual_size = print_using_actual_size;
386 final void setReplaceUnderscoresInNhParsing( final boolean nh_parsing_replace_underscores ) {
387 _nh_parsing_replace_underscores = nh_parsing_replace_underscores;
390 final void setScaleBarLength( final double scale_bar_length ) {
391 _scale_bar_length = scale_bar_length;
394 final void setSearchCaseSensitive( final boolean search_case_sensitive ) {
395 _search_case_sensitive = search_case_sensitive;
398 final void setShowBranchLengthValues( final boolean show_branch_length_values ) {
399 _show_branch_length_values = show_branch_length_values;
402 void setShowConfidenceStddev( final boolean show_confidence_stddev ) {
403 _show_confidence_stddev = show_confidence_stddev;
406 void setShowDefaultNodeShapesExternal( final boolean show_default_node_shapes_external ) {
407 _show_default_node_shapes_external = show_default_node_shapes_external;
410 void setShowDefaultNodeShapesInternal( final boolean show_default_node_shapes_internal ) {
411 _show_default_node_shapes_internal = show_default_node_shapes_internal;
414 final void setShowOverview( final boolean show_overview ) {
415 _show_overview = show_overview;
418 final void setShowScale( final boolean show_scale ) {
419 _show_scale = show_scale;
422 void setTaxonomyColorizeNodeShapes( final boolean taxonomy_colorize_node_shapes ) {
423 _taxonomy_colorize_node_shapes = taxonomy_colorize_node_shapes;
426 final void setTaxonomyExtraction( final TAXONOMY_EXTRACTION taxonomy_extraction ) {
427 _taxonomy_extraction = taxonomy_extraction;
430 final private void init() {
431 _default_node_shape = NodeShape.CIRCLE;
432 _default_node_fill = NodeFill.GRADIENT;
433 _default_node_shape_size = Constants.DEFAULT_NODE_SHAPE_SIZE_DEFAULT;
434 _taxonomy_colorize_node_shapes = false;
435 _show_branch_length_values = false;
436 _internal_number_are_confidence_for_nh_parsing = false;
438 _antialias_screen = false;
439 _antialias_print = true;
440 _graphics_export_visible_only = false;
442 _background_color_gradient = false;
443 _show_default_node_shapes_internal = false;
444 _show_default_node_shapes_external = false;
445 if ( AptxUtil.isUsOrCanada() ) {
446 _print_size_x = Constants.US_LETTER_SIZE_X;
447 _print_size_y = Constants.US_LETTER_SIZE_Y;
450 _print_size_x = Constants.A4_SIZE_X;
451 _print_size_y = Constants.A4_SIZE_Y;
453 _min_confidence_value = MIN_CONFIDENCE_DEFAULT;
454 _print_black_and_white = false;
455 _print_using_actual_size = false;
456 _graphics_export_using_actual_size = true;
457 _phylogeny_graphics_type = PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR;
458 _base_font = new Font( Configuration.getDefaultFontFamilyName(), Font.PLAIN, 10 );
459 _match_whole_terms_only = false;
460 _search_case_sensitive = false;
461 _print_line_width = Constants.PDF_LINE_WIDTH_DEFAULT;
462 _show_overview = true;
463 _ov_placement = OVERVIEW_PLACEMENT_TYPE.UPPER_LEFT;
464 _node_label_direction = NODE_LABEL_DIRECTION.HORIZONTAL;
465 _inverse_search_result = false;
466 _scale_bar_length = 0.0;
467 _number_of_digits_after_comma_for_branch_length_values = Constants.NUMBER_OF_DIGITS_AFTER_COMMA_FOR_BRANCH_LENGTH_VALUES_DEFAULT;
468 _number_of_digits_after_comma_for_confidence_values = Constants.NUMBER_OF_DIGITS_AFTER_COMMA_FOR_CONFIDENCE_VALUES_DEFAULT;
469 _nh_parsing_replace_underscores = false;
470 _taxonomy_extraction = TAXONOMY_EXTRACTION.NO;
471 _cladogram_type = Constants.CLADOGRAM_TYPE_DEFAULT;
472 _show_domain_labels = true;
473 _show_annotation_ref_source = true;
474 setAbbreviateScientificTaxonNames( false );
475 _color_labels_same_as_parent_branch = false;
476 _show_confidence_stddev = true;
477 _nh_conversion_support_value_style = NH_CONVERSION_SUPPORT_VALUE_STYLE.NONE;
478 _ext_desc_data_to_return = NODE_DATA.UNKNOWN;
481 final private void setNumberOfDigitsAfterCommaForBranchLength( final short number_of_digits_after_comma_for_branch_length_values ) {
482 _number_of_digits_after_comma_for_branch_length_values = number_of_digits_after_comma_for_branch_length_values;
485 final private void setNumberOfDigitsAfterCommaForConfidenceValues( final short number_of_digits_after_comma_for_confidence_values ) {
486 _number_of_digits_after_comma_for_confidence_values = number_of_digits_after_comma_for_confidence_values;
489 public final static Options createInstance( final Configuration configuration ) {
490 final Options instance = createDefaultInstance();
491 if ( configuration != null ) {
492 instance.setAntialiasScreen( configuration.isAntialiasScreen() );
493 instance.setShowScale( configuration.isShowScale() );
494 instance.setShowBranchLengthValues( configuration.isShowBranchLengthValues() );
495 instance.setShowOverview( configuration.isShowOverview() );
496 instance.setCladogramType( configuration.getCladogramType() );
497 instance.setOvPlacement( configuration.getOvPlacement() );
498 instance.setPrintLineWidth( configuration.getPrintLineWidth() );
499 instance.setNodeLabelDirection( configuration.getNodeLabelDirection() );
500 instance.setBackgroundColorGradient( configuration.isBackgroundColorGradient() );
501 if ( configuration.getNumberOfDigitsAfterCommaForBranchLengthValues() >= 0 ) {
502 instance.setNumberOfDigitsAfterCommaForBranchLength( configuration
503 .getNumberOfDigitsAfterCommaForBranchLengthValues() );
505 if ( configuration.getNumberOfDigitsAfterCommaForConfidenceValues() >= 0 ) {
506 instance.setNumberOfDigitsAfterCommaForConfidenceValues( configuration
507 .getNumberOfDigitsAfterCommaForConfidenceValues() );
509 instance.setTaxonomyExtraction( configuration.getTaxonomyExtraction() );
510 instance.setReplaceUnderscoresInNhParsing( configuration.isReplaceUnderscoresInNhParsing() );
511 instance.setInternalNumberAreConfidenceForNhParsing( configuration
512 .isInternalNumberAreConfidenceForNhParsing() );
513 instance.setEditable( configuration.isEditable() );
514 instance.setColorLabelsSameAsParentBranch( configuration.isColorLabelsSameAsParentBranch() );
515 instance.setShowDomainLabels( configuration.isShowDomainLabels() );
516 instance.setShowAnnotationRefSource( configuration.isShowAnnotationRefSource() );
517 instance.setAbbreviateScientificTaxonNames( configuration.isAbbreviateScientificTaxonNames() );
518 if ( configuration.getMinConfidenceValue() != MIN_CONFIDENCE_DEFAULT ) {
519 instance.setMinConfidenceValue( configuration.getMinConfidenceValue() );
521 if ( configuration.getGraphicsExportX() > 0 ) {
522 instance.setPrintSizeX( configuration.getGraphicsExportX() );
524 if ( configuration.getGraphicsExportY() > 0 ) {
525 instance.setPrintSizeY( configuration.getGraphicsExportY() );
527 if ( configuration.getBaseFontSize() > 0 ) {
528 instance.setBaseFont( instance.getBaseFont().deriveFont( ( float ) configuration.getBaseFontSize() ) );
530 if ( !ForesterUtil.isEmpty( configuration.getBaseFontFamilyName() ) ) {
531 instance.setBaseFont( new Font( configuration.getBaseFontFamilyName(), Font.PLAIN, instance
532 .getBaseFont().getSize() ) );
534 if ( configuration.getPhylogenyGraphicsType() != null ) {
535 instance.setPhylogenyGraphicsType( configuration.getPhylogenyGraphicsType() );
537 if ( configuration.getDefaultNodeFill() != null ) {
538 instance.setDefaultNodeFill( configuration.getDefaultNodeFill() );
540 if ( configuration.getDefaultNodeShape() != null ) {
541 instance.setDefaultNodeShape( configuration.getDefaultNodeShape() );
543 if ( configuration.getDefaultNodeShapeSize() >= 0 ) {
544 instance.setDefaultNodeShapeSize( configuration.getDefaultNodeShapeSize() );
546 instance.setTaxonomyColorizeNodeShapes( configuration.isTaxonomyColorizeNodeShapes() );
547 instance.setShowDefaultNodeShapesInternal( configuration.isShowDefaultNodeShapesInternal() );
548 instance.setShowDefaultNodeShapesExternal( configuration.isShowDefaultNodeShapesExternal() );
549 if ( configuration.getExtDescNodeDataToReturn() != null ) {
550 instance.setExtDescNodeDataToReturn( configuration.getExtDescNodeDataToReturn() );
556 final static Options createDefaultInstance() {
557 return new Options();
560 public static enum CLADOGRAM_TYPE {
561 NON_LINED_UP, EXT_NODE_SUM_DEP, TOTAL_NODE_SUM_DEP;
564 public static enum NODE_LABEL_DIRECTION {
568 public static enum PHYLOGENY_GRAPHICS_TYPE {
569 RECTANGULAR, TRIANGULAR, EURO_STYLE, ROUNDED, CONVEX, CURVED, UNROOTED, CIRCULAR;
572 static enum OVERVIEW_PLACEMENT_TYPE {
573 UPPER_LEFT( "upper left" ),
574 UPPER_RIGHT( "upper right" ),
575 LOWER_LEFT( "lower left" ),
576 LOWER_RIGHT( "lower right" );
578 private final String _name;
580 private OVERVIEW_PLACEMENT_TYPE( final String name ) {
585 public String toString() {
589 public String toTag() {
590 return toString().replaceAll( " ", "_" );
594 public boolean isAllowFontSizeChange() {