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 _color_by_taxonomic_group;
46 private boolean _show_branch_length_values;
47 private boolean _internal_number_are_confidence_for_nh_parsing;
48 private boolean _show_scale;
49 private boolean _show_overview;
50 private boolean _antialias_screen;
51 private boolean _antialias_print;
52 private boolean _graphics_export_visible_only;
53 private int _print_size_x;
54 private int _print_size_y;
55 private double _min_confidence_value;
56 private boolean _print_black_and_white;
57 private boolean _print_using_actual_size;
58 private boolean _graphics_export_using_actual_size;
59 private PHYLOGENY_GRAPHICS_TYPE _phylogeny_graphics_type;
60 private CLADOGRAM_TYPE _cladogram_type;
61 private OVERVIEW_PLACEMENT_TYPE _ov_placement;
62 private NODE_LABEL_DIRECTION _node_label_direction;
63 private Font _base_font;
64 private boolean _match_whole_terms_only;
65 private boolean _search_case_sensitive;
66 private float _print_line_width;
67 private boolean _inverse_search_result;
68 private double _scale_bar_length;
69 private short _number_of_digits_after_comma_for_confidence_values;
70 private short _number_of_digits_after_comma_for_branch_length_values;
71 private boolean _nh_parsing_replace_underscores;
72 private TAXONOMY_EXTRACTION _taxonomy_extraction;
73 private boolean _editable;
74 private boolean _background_color_gradient;
75 private boolean _show_domain_labels;
76 private boolean _show_annotation_ref_source;
77 private boolean _color_labels_same_as_parent_branch;
78 private boolean _abbreviate_scientific_names;
79 private NodeVisualization.NodeShape _default_node_shape;
80 private NodeVisualization.NodeFill _default_node_fill;
81 private short _default_node_shape_size;
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 final boolean isColorByTaxonomicGroup() {
261 return _color_by_taxonomic_group;
264 boolean isShowConfidenceStddev() {
265 return _show_confidence_stddev;
268 boolean isShowDefaultNodeShapesExternal() {
269 return _show_default_node_shapes_external;
272 boolean isShowDefaultNodeShapesInternal() {
273 return _show_default_node_shapes_internal;
276 final boolean isShowOverview() {
277 return _show_overview;
280 final boolean isShowScale() {
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 final void setColorByTaxonomicGroup( final boolean color_by_taxonomic_group ) {
403 _color_by_taxonomic_group = color_by_taxonomic_group;
406 void setShowConfidenceStddev( final boolean show_confidence_stddev ) {
407 _show_confidence_stddev = show_confidence_stddev;
410 void setShowDefaultNodeShapesExternal( final boolean show_default_node_shapes_external ) {
411 _show_default_node_shapes_external = show_default_node_shapes_external;
414 void setShowDefaultNodeShapesInternal( final boolean show_default_node_shapes_internal ) {
415 _show_default_node_shapes_internal = show_default_node_shapes_internal;
418 final void setShowOverview( final boolean show_overview ) {
419 _show_overview = show_overview;
422 final void setShowScale( final boolean show_scale ) {
423 _show_scale = show_scale;
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 _show_branch_length_values = false;
435 _internal_number_are_confidence_for_nh_parsing = false;
437 _antialias_screen = true;
438 _antialias_print = true;
439 _graphics_export_visible_only = false;
441 _background_color_gradient = false;
442 _show_default_node_shapes_internal = false;
443 _show_default_node_shapes_external = false;
444 if ( AptxUtil.isUsOrCanada() ) {
445 _print_size_x = Constants.US_LETTER_SIZE_X;
446 _print_size_y = Constants.US_LETTER_SIZE_Y;
449 _print_size_x = Constants.A4_SIZE_X;
450 _print_size_y = Constants.A4_SIZE_Y;
452 _min_confidence_value = MIN_CONFIDENCE_DEFAULT;
453 _print_black_and_white = false;
454 _print_using_actual_size = false;
455 _graphics_export_using_actual_size = true;
456 _phylogeny_graphics_type = PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR;
457 _base_font = new Font( Configuration.getDefaultFontFamilyName(), Font.PLAIN, 10 );
458 _match_whole_terms_only = false;
459 _search_case_sensitive = false;
460 _print_line_width = Constants.PDF_LINE_WIDTH_DEFAULT;
461 _show_overview = true;
462 _ov_placement = OVERVIEW_PLACEMENT_TYPE.UPPER_LEFT;
463 _node_label_direction = NODE_LABEL_DIRECTION.HORIZONTAL;
464 _inverse_search_result = false;
465 _scale_bar_length = 0.0;
466 _number_of_digits_after_comma_for_branch_length_values = Constants.NUMBER_OF_DIGITS_AFTER_COMMA_FOR_BRANCH_LENGTH_VALUES_DEFAULT;
467 _number_of_digits_after_comma_for_confidence_values = Constants.NUMBER_OF_DIGITS_AFTER_COMMA_FOR_CONFIDENCE_VALUES_DEFAULT;
468 _nh_parsing_replace_underscores = false;
469 _taxonomy_extraction = TAXONOMY_EXTRACTION.NO;
470 _cladogram_type = Constants.CLADOGRAM_TYPE_DEFAULT;
471 _show_domain_labels = true;
472 _show_annotation_ref_source = true;
473 setAbbreviateScientificTaxonNames( false );
474 _color_labels_same_as_parent_branch = false;
475 _show_confidence_stddev = true;
476 _nh_conversion_support_value_style = NH_CONVERSION_SUPPORT_VALUE_STYLE.NONE;
477 _ext_desc_data_to_return = NODE_DATA.UNKNOWN;
480 final private void setNumberOfDigitsAfterCommaForBranchLength( final short number_of_digits_after_comma_for_branch_length_values ) {
481 _number_of_digits_after_comma_for_branch_length_values = number_of_digits_after_comma_for_branch_length_values;
484 final private void setNumberOfDigitsAfterCommaForConfidenceValues( final short number_of_digits_after_comma_for_confidence_values ) {
485 _number_of_digits_after_comma_for_confidence_values = number_of_digits_after_comma_for_confidence_values;
488 public final static Options createInstance( final Configuration configuration ) {
489 final Options instance = createDefaultInstance();
490 if ( configuration != null ) {
491 instance.setAntialiasScreen( configuration.isAntialiasScreen() );
492 instance.setShowScale( configuration.isShowScale() );
493 instance.setShowBranchLengthValues( configuration.isShowBranchLengthValues() );
494 instance.setShowOverview( configuration.isShowOverview() );
495 instance.setColorByTaxonomicGroup( configuration.isColorByTaxonomicGroup() );
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.setShowDefaultNodeShapesInternal( configuration.isShowDefaultNodeShapesInternal() );
547 instance.setShowDefaultNodeShapesExternal( configuration.isShowDefaultNodeShapesExternal() );
548 if ( configuration.getExtDescNodeDataToReturn() != null ) {
549 instance.setExtDescNodeDataToReturn( configuration.getExtDescNodeDataToReturn() );
555 final static Options createDefaultInstance() {
556 return new Options();
559 public static enum CLADOGRAM_TYPE {
560 NON_LINED_UP, EXT_NODE_SUM_DEP, TOTAL_NODE_SUM_DEP;
563 public static enum NODE_LABEL_DIRECTION {
567 public static enum PHYLOGENY_GRAPHICS_TYPE {
568 RECTANGULAR, TRIANGULAR, EURO_STYLE, ROUNDED, CONVEX, CURVED, UNROOTED, CIRCULAR;
571 static enum OVERVIEW_PLACEMENT_TYPE {
572 UPPER_LEFT( "upper left" ),
573 UPPER_RIGHT( "upper right" ),
574 LOWER_LEFT( "lower left" ),
575 LOWER_RIGHT( "lower right" );
577 private final String _name;
579 private OVERVIEW_PLACEMENT_TYPE( final String name ) {
584 public String toString() {
588 public String toTag() {
589 return toString().replaceAll( " ", "_" );
593 public boolean isAllowFontSizeChange() {