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 _taxonomy_colorize_node_shapes;
83 private boolean _show_default_node_shapes_internal;
84 private boolean _show_default_node_shapes_external;
85 private boolean _show_confidence_stddev;
86 private NH_CONVERSION_SUPPORT_VALUE_STYLE _nh_conversion_support_value_style;
87 private NODE_DATA _ext_desc_data_to_return;
93 public NodeData.NODE_DATA getExtDescNodeDataToReturn() {
94 return _ext_desc_data_to_return;
97 public final boolean isShowDomainLabels() {
98 return _show_domain_labels;
101 public final boolean isShowAnnotationRefSource() {
102 return _show_annotation_ref_source;
105 public final void setShowAnnotationRefSource( final boolean show_annotation_ref_source ) {
106 _show_annotation_ref_source = show_annotation_ref_source;
109 public void setBackgroundColorGradient( final boolean background_color_gradient ) {
110 _background_color_gradient = background_color_gradient;
113 public void setColorLabelsSameAsParentBranch( final boolean color_labels_same_as_parent_branch ) {
114 _color_labels_same_as_parent_branch = color_labels_same_as_parent_branch;
117 public void setExtDescNodeDataToReturn( final NODE_DATA ext_desc_data_to_return ) {
118 _ext_desc_data_to_return = ext_desc_data_to_return;
121 public void setShowDomainLabels( final boolean show_domain_labels ) {
122 _show_domain_labels = show_domain_labels;
125 final Font getBaseFont() {
129 final CLADOGRAM_TYPE getCladogramType() {
130 return _cladogram_type;
133 final NodeFill getDefaultNodeFill() {
134 return _default_node_fill;
137 final NodeShape getDefaultNodeShape() {
138 return _default_node_shape;
141 final short getDefaultNodeShapeSize() {
142 return _default_node_shape_size;
145 final double getMinConfidenceValue() {
146 return _min_confidence_value;
149 NH_CONVERSION_SUPPORT_VALUE_STYLE getNhConversionSupportValueStyle() {
150 return _nh_conversion_support_value_style;
153 final NODE_LABEL_DIRECTION getNodeLabelDirection() {
154 return _node_label_direction;
157 final short getNumberOfDigitsAfterCommaForBranchLengthValues() {
158 return _number_of_digits_after_comma_for_branch_length_values;
161 final short getNumberOfDigitsAfterCommaForConfidenceValues() {
162 return _number_of_digits_after_comma_for_confidence_values;
165 final OVERVIEW_PLACEMENT_TYPE getOvPlacement() {
166 return _ov_placement;
169 final PHYLOGENY_GRAPHICS_TYPE getPhylogenyGraphicsType() {
170 return _phylogeny_graphics_type;
173 final float getPrintLineWidth() {
174 return _print_line_width;
177 final int getPrintSizeX() {
178 return _print_size_x;
181 final int getPrintSizeY() {
182 return _print_size_y;
185 final double getScaleBarLength() {
186 return _scale_bar_length;
189 final TAXONOMY_EXTRACTION getTaxonomyExtraction() {
190 return _taxonomy_extraction;
193 final boolean isAbbreviateScientificTaxonNames() {
194 return _abbreviate_scientific_names;
197 boolean isAllowMagnificationOfTaxonomyImages() {
201 final boolean isAntialiasPrint() {
202 return _antialias_print;
205 final boolean isAntialiasScreen() {
206 return _antialias_screen;
209 final boolean isBackgroundColorGradient() {
210 return _background_color_gradient;
213 final boolean isColorLabelsSameAsParentBranch() {
214 return _color_labels_same_as_parent_branch;
217 final boolean isEditable() {
221 final boolean isGraphicsExportUsingActualSize() {
222 return _graphics_export_using_actual_size;
225 final boolean isGraphicsExportVisibleOnly() {
226 return _graphics_export_visible_only;
229 final boolean isInternalNumberAreConfidenceForNhParsing() {
230 return _internal_number_are_confidence_for_nh_parsing;
233 final boolean isInverseSearchResult() {
234 return _inverse_search_result;
237 final boolean isMatchWholeTermsOnly() {
238 return _match_whole_terms_only;
241 final boolean isPrintBlackAndWhite() {
242 return _print_black_and_white;
245 final boolean isPrintUsingActualSize() {
246 return _print_using_actual_size;
249 final boolean isReplaceUnderscoresInNhParsing() {
250 return _nh_parsing_replace_underscores;
253 final boolean isSearchCaseSensitive() {
254 return _search_case_sensitive;
257 final boolean isShowBranchLengthValues() {
258 return _show_branch_length_values;
261 final boolean isColorByTaxonomicGroup() {
262 return _color_by_taxonomic_group;
265 boolean isShowConfidenceStddev() {
266 return _show_confidence_stddev;
269 boolean isShowDefaultNodeShapesExternal() {
270 return _show_default_node_shapes_external;
273 boolean isShowDefaultNodeShapesInternal() {
274 return _show_default_node_shapes_internal;
277 final boolean isShowOverview() {
278 return _show_overview;
281 final boolean isShowScale() {
285 boolean isTaxonomyColorizeNodeShapes() {
286 return _taxonomy_colorize_node_shapes;
289 final void setAbbreviateScientificTaxonNames( final boolean abbreviate_scientific_names ) {
290 _abbreviate_scientific_names = abbreviate_scientific_names;
293 final void setAntialiasPrint( final boolean antialias_print ) {
294 _antialias_print = antialias_print;
297 final void setAntialiasScreen( final boolean antialias_screen ) {
298 _antialias_screen = antialias_screen;
301 final void setBaseFont( final Font base_font ) {
302 _base_font = base_font;
305 final void setCladogramType( final CLADOGRAM_TYPE cladogram_type ) {
306 _cladogram_type = cladogram_type;
309 final void setDefaultNodeFill( final NodeFill default_node_fill ) {
310 _default_node_fill = default_node_fill;
313 final void setDefaultNodeShape( final NodeShape default_node_shape ) {
314 _default_node_shape = default_node_shape;
317 final void setDefaultNodeShapeSize( final short default_node_shape_size ) {
318 _default_node_shape_size = default_node_shape_size;
321 final void setEditable( final boolean editable ) {
322 _editable = editable;
325 final void setGraphicsExportUsingActualSize( final boolean graphics_export_using_actual_size ) {
326 _graphics_export_using_actual_size = graphics_export_using_actual_size;
327 if ( !graphics_export_using_actual_size ) {
328 setGraphicsExportVisibleOnly( false );
332 final void setGraphicsExportVisibleOnly( final boolean graphics_export_visible_only ) {
333 _graphics_export_visible_only = graphics_export_visible_only;
334 if ( graphics_export_visible_only ) {
335 setGraphicsExportUsingActualSize( true );
339 final void setInternalNumberAreConfidenceForNhParsing( final boolean internal_number_are_confidence_for_nh_parsing ) {
340 _internal_number_are_confidence_for_nh_parsing = internal_number_are_confidence_for_nh_parsing;
343 final void setInverseSearchResult( final boolean inverse_search_result ) {
344 _inverse_search_result = inverse_search_result;
347 final void setMatchWholeTermsOnly( final boolean search_whole_words_only ) {
348 _match_whole_terms_only = search_whole_words_only;
351 final void setMinConfidenceValue( final double min_confidence_value ) {
352 _min_confidence_value = min_confidence_value;
355 void setNhConversionSupportValueStyle( final NH_CONVERSION_SUPPORT_VALUE_STYLE nh_conversion_support_value_style ) {
356 _nh_conversion_support_value_style = nh_conversion_support_value_style;
359 final void setNodeLabelDirection( final NODE_LABEL_DIRECTION node_label_direction ) {
360 _node_label_direction = node_label_direction;
363 final void setOvPlacement( final OVERVIEW_PLACEMENT_TYPE ov_placement ) {
364 _ov_placement = ov_placement;
367 final void setPhylogenyGraphicsType( final PHYLOGENY_GRAPHICS_TYPE phylogeny_graphics_type ) {
368 _phylogeny_graphics_type = phylogeny_graphics_type;
371 final void setPrintBlackAndWhite( final boolean print_black_and_white ) {
372 _print_black_and_white = print_black_and_white;
375 final void setPrintLineWidth( final float print_line_width ) {
376 _print_line_width = print_line_width;
379 final void setPrintSizeX( final int print_size_x ) {
380 _print_size_x = print_size_x;
383 final void setPrintSizeY( final int print_size_y ) {
384 _print_size_y = print_size_y;
387 final void setPrintUsingActualSize( final boolean print_using_actual_size ) {
388 _print_using_actual_size = print_using_actual_size;
391 final void setReplaceUnderscoresInNhParsing( final boolean nh_parsing_replace_underscores ) {
392 _nh_parsing_replace_underscores = nh_parsing_replace_underscores;
395 final void setScaleBarLength( final double scale_bar_length ) {
396 _scale_bar_length = scale_bar_length;
399 final void setSearchCaseSensitive( final boolean search_case_sensitive ) {
400 _search_case_sensitive = search_case_sensitive;
403 final void setShowBranchLengthValues( final boolean show_branch_length_values ) {
404 _show_branch_length_values = show_branch_length_values;
407 final void setColorByTaxonomicGroup( final boolean color_by_taxonomic_group ) {
408 _color_by_taxonomic_group = color_by_taxonomic_group;
411 void setShowConfidenceStddev( final boolean show_confidence_stddev ) {
412 _show_confidence_stddev = show_confidence_stddev;
415 void setShowDefaultNodeShapesExternal( final boolean show_default_node_shapes_external ) {
416 _show_default_node_shapes_external = show_default_node_shapes_external;
419 void setShowDefaultNodeShapesInternal( final boolean show_default_node_shapes_internal ) {
420 _show_default_node_shapes_internal = show_default_node_shapes_internal;
423 final void setShowOverview( final boolean show_overview ) {
424 _show_overview = show_overview;
427 final void setShowScale( final boolean show_scale ) {
428 _show_scale = show_scale;
431 void setTaxonomyColorizeNodeShapes( final boolean taxonomy_colorize_node_shapes ) {
432 _taxonomy_colorize_node_shapes = taxonomy_colorize_node_shapes;
435 final void setTaxonomyExtraction( final TAXONOMY_EXTRACTION taxonomy_extraction ) {
436 _taxonomy_extraction = taxonomy_extraction;
439 final private void init() {
440 _default_node_shape = NodeShape.CIRCLE;
441 _default_node_fill = NodeFill.GRADIENT;
442 _default_node_shape_size = Constants.DEFAULT_NODE_SHAPE_SIZE_DEFAULT;
443 _taxonomy_colorize_node_shapes = false;
444 _show_branch_length_values = false;
445 _internal_number_are_confidence_for_nh_parsing = false;
447 _antialias_screen = false;
448 _antialias_print = true;
449 _graphics_export_visible_only = false;
451 _background_color_gradient = false;
452 _show_default_node_shapes_internal = false;
453 _show_default_node_shapes_external = false;
454 if ( AptxUtil.isUsOrCanada() ) {
455 _print_size_x = Constants.US_LETTER_SIZE_X;
456 _print_size_y = Constants.US_LETTER_SIZE_Y;
459 _print_size_x = Constants.A4_SIZE_X;
460 _print_size_y = Constants.A4_SIZE_Y;
462 _min_confidence_value = MIN_CONFIDENCE_DEFAULT;
463 _print_black_and_white = false;
464 _print_using_actual_size = false;
465 _graphics_export_using_actual_size = true;
466 _phylogeny_graphics_type = PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR;
467 _base_font = new Font( Configuration.getDefaultFontFamilyName(), Font.PLAIN, 10 );
468 _match_whole_terms_only = false;
469 _search_case_sensitive = false;
470 _print_line_width = Constants.PDF_LINE_WIDTH_DEFAULT;
471 _show_overview = true;
472 _ov_placement = OVERVIEW_PLACEMENT_TYPE.UPPER_LEFT;
473 _node_label_direction = NODE_LABEL_DIRECTION.HORIZONTAL;
474 _inverse_search_result = false;
475 _scale_bar_length = 0.0;
476 _number_of_digits_after_comma_for_branch_length_values = Constants.NUMBER_OF_DIGITS_AFTER_COMMA_FOR_BRANCH_LENGTH_VALUES_DEFAULT;
477 _number_of_digits_after_comma_for_confidence_values = Constants.NUMBER_OF_DIGITS_AFTER_COMMA_FOR_CONFIDENCE_VALUES_DEFAULT;
478 _nh_parsing_replace_underscores = false;
479 _taxonomy_extraction = TAXONOMY_EXTRACTION.NO;
480 _cladogram_type = Constants.CLADOGRAM_TYPE_DEFAULT;
481 _show_domain_labels = true;
482 _show_annotation_ref_source = true;
483 setAbbreviateScientificTaxonNames( false );
484 _color_labels_same_as_parent_branch = false;
485 _show_confidence_stddev = true;
486 _nh_conversion_support_value_style = NH_CONVERSION_SUPPORT_VALUE_STYLE.NONE;
487 _ext_desc_data_to_return = NODE_DATA.UNKNOWN;
490 final private void setNumberOfDigitsAfterCommaForBranchLength( final short number_of_digits_after_comma_for_branch_length_values ) {
491 _number_of_digits_after_comma_for_branch_length_values = number_of_digits_after_comma_for_branch_length_values;
494 final private void setNumberOfDigitsAfterCommaForConfidenceValues( final short number_of_digits_after_comma_for_confidence_values ) {
495 _number_of_digits_after_comma_for_confidence_values = number_of_digits_after_comma_for_confidence_values;
498 public final static Options createInstance( final Configuration configuration ) {
499 final Options instance = createDefaultInstance();
500 if ( configuration != null ) {
501 instance.setAntialiasScreen( configuration.isAntialiasScreen() );
502 instance.setShowScale( configuration.isShowScale() );
503 instance.setShowBranchLengthValues( configuration.isShowBranchLengthValues() );
504 instance.setShowOverview( configuration.isShowOverview() );
505 instance.setColorByTaxonomicGroup( configuration.isColorByTaxonomicGroup() );
506 instance.setCladogramType( configuration.getCladogramType() );
507 instance.setOvPlacement( configuration.getOvPlacement() );
508 instance.setPrintLineWidth( configuration.getPrintLineWidth() );
509 instance.setNodeLabelDirection( configuration.getNodeLabelDirection() );
510 instance.setBackgroundColorGradient( configuration.isBackgroundColorGradient() );
511 if ( configuration.getNumberOfDigitsAfterCommaForBranchLengthValues() >= 0 ) {
512 instance.setNumberOfDigitsAfterCommaForBranchLength( configuration
513 .getNumberOfDigitsAfterCommaForBranchLengthValues() );
515 if ( configuration.getNumberOfDigitsAfterCommaForConfidenceValues() >= 0 ) {
516 instance.setNumberOfDigitsAfterCommaForConfidenceValues( configuration
517 .getNumberOfDigitsAfterCommaForConfidenceValues() );
519 instance.setTaxonomyExtraction( configuration.getTaxonomyExtraction() );
520 instance.setReplaceUnderscoresInNhParsing( configuration.isReplaceUnderscoresInNhParsing() );
521 instance.setInternalNumberAreConfidenceForNhParsing( configuration
522 .isInternalNumberAreConfidenceForNhParsing() );
523 instance.setEditable( configuration.isEditable() );
524 instance.setColorLabelsSameAsParentBranch( configuration.isColorLabelsSameAsParentBranch() );
525 instance.setShowDomainLabels( configuration.isShowDomainLabels() );
526 instance.setShowAnnotationRefSource( configuration.isShowAnnotationRefSource() );
527 instance.setAbbreviateScientificTaxonNames( configuration.isAbbreviateScientificTaxonNames() );
528 if ( configuration.getMinConfidenceValue() != MIN_CONFIDENCE_DEFAULT ) {
529 instance.setMinConfidenceValue( configuration.getMinConfidenceValue() );
531 if ( configuration.getGraphicsExportX() > 0 ) {
532 instance.setPrintSizeX( configuration.getGraphicsExportX() );
534 if ( configuration.getGraphicsExportY() > 0 ) {
535 instance.setPrintSizeY( configuration.getGraphicsExportY() );
537 if ( configuration.getBaseFontSize() > 0 ) {
538 instance.setBaseFont( instance.getBaseFont().deriveFont( ( float ) configuration.getBaseFontSize() ) );
540 if ( !ForesterUtil.isEmpty( configuration.getBaseFontFamilyName() ) ) {
541 instance.setBaseFont( new Font( configuration.getBaseFontFamilyName(), Font.PLAIN, instance
542 .getBaseFont().getSize() ) );
544 if ( configuration.getPhylogenyGraphicsType() != null ) {
545 instance.setPhylogenyGraphicsType( configuration.getPhylogenyGraphicsType() );
547 if ( configuration.getDefaultNodeFill() != null ) {
548 instance.setDefaultNodeFill( configuration.getDefaultNodeFill() );
550 if ( configuration.getDefaultNodeShape() != null ) {
551 instance.setDefaultNodeShape( configuration.getDefaultNodeShape() );
553 if ( configuration.getDefaultNodeShapeSize() >= 0 ) {
554 instance.setDefaultNodeShapeSize( configuration.getDefaultNodeShapeSize() );
556 instance.setTaxonomyColorizeNodeShapes( configuration.isTaxonomyColorizeNodeShapes() );
557 instance.setShowDefaultNodeShapesInternal( configuration.isShowDefaultNodeShapesInternal() );
558 instance.setShowDefaultNodeShapesExternal( configuration.isShowDefaultNodeShapesExternal() );
559 if ( configuration.getExtDescNodeDataToReturn() != null ) {
560 instance.setExtDescNodeDataToReturn( configuration.getExtDescNodeDataToReturn() );
566 final static Options createDefaultInstance() {
567 return new Options();
570 public static enum CLADOGRAM_TYPE {
571 NON_LINED_UP, EXT_NODE_SUM_DEP, TOTAL_NODE_SUM_DEP;
574 public static enum NODE_LABEL_DIRECTION {
578 public static enum PHYLOGENY_GRAPHICS_TYPE {
579 RECTANGULAR, TRIANGULAR, EURO_STYLE, ROUNDED, CONVEX, CURVED, UNROOTED, CIRCULAR;
582 static enum OVERVIEW_PLACEMENT_TYPE {
583 UPPER_LEFT( "upper left" ),
584 UPPER_RIGHT( "upper right" ),
585 LOWER_LEFT( "lower left" ),
586 LOWER_RIGHT( "lower right" );
588 private final String _name;
590 private OVERVIEW_PLACEMENT_TYPE( final String name ) {
595 public String toString() {
599 public String toTag() {
600 return toString().replaceAll( " ", "_" );
604 public boolean isAllowFontSizeChange() {