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: www.phylosoft.org/forester
26 package org.forester.archaeopteryx;
30 import org.forester.phylogeny.PhylogenyNodeI.NH_CONVERSION_SUPPORT_VALUE_STYLE;
31 import org.forester.phylogeny.data.NodeVisualization;
32 import org.forester.phylogeny.data.NodeVisualization.NodeFill;
33 import org.forester.phylogeny.data.NodeVisualization.NodeShape;
34 import org.forester.util.ForesterUtil;
37 * This is to hold changeable options.
39 final public class Options {
41 static final double MIN_CONFIDENCE_DEFAULT = 0.0;
42 private boolean _show_branch_length_values;
43 private boolean _internal_number_are_confidence_for_nh_parsing;
44 private boolean _show_scale;
45 private boolean _show_overview;
46 private boolean _antialias_screen;
47 private boolean _antialias_print;
48 private boolean _graphics_export_visible_only;
49 private int _print_size_x;
50 private int _print_size_y;
51 private double _min_confidence_value;
52 private boolean _print_black_and_white;
53 private boolean _print_using_actual_size;
54 private boolean _graphics_export_using_actual_size;
55 private PHYLOGENY_GRAPHICS_TYPE _phylogeny_graphics_type;
56 private CLADOGRAM_TYPE _cladogram_type;
57 private OVERVIEW_PLACEMENT_TYPE _ov_placement;
58 private NODE_LABEL_DIRECTION _node_label_direction;
59 private Font _base_font;
60 private boolean _match_whole_terms_only;
61 private boolean _search_case_sensitive;
62 private float _print_line_width;
63 private boolean _inverse_search_result;
64 private double _scale_bar_length;
65 private short _number_of_digits_after_comma_for_confidence_values;
66 private short _number_of_digits_after_comma_for_branch_length_values;
67 private boolean _nh_parsing_replace_underscores;
68 private boolean _nh_parsing_extract_pfam_taxonomy_codes;
69 private boolean _editable;
70 private boolean _background_color_gradient;
71 private boolean _show_domain_labels;
72 private boolean _color_labels_same_as_parent_branch;
73 private boolean _abbreviate_scientific_names;
74 private NodeVisualization.NodeShape _default_node_shape;
75 private NodeVisualization.NodeFill _default_node_fill;
76 private short _default_node_shape_size;
77 private boolean _taxonomy_colorize_node_shapes;
78 private boolean _show_default_node_shapes;
79 private boolean _show_confidence_stddev;
80 private NH_CONVERSION_SUPPORT_VALUE_STYLE _nh_conversion_support_value_style;
86 final Font getBaseFont() {
90 final CLADOGRAM_TYPE getCladogramType() {
91 return _cladogram_type;
94 final NodeFill getDefaultNodeFill() {
95 return _default_node_fill;
98 final NodeShape getDefaultNodeShape() {
99 return _default_node_shape;
102 final short getDefaultNodeShapeSize() {
103 return _default_node_shape_size;
106 final double getMinConfidenceValue() {
107 return _min_confidence_value;
110 final NODE_LABEL_DIRECTION getNodeLabelDirection() {
111 return _node_label_direction;
114 final short getNumberOfDigitsAfterCommaForBranchLengthValues() {
115 return _number_of_digits_after_comma_for_branch_length_values;
118 final short getNumberOfDigitsAfterCommaForConfidenceValues() {
119 return _number_of_digits_after_comma_for_confidence_values;
122 final OVERVIEW_PLACEMENT_TYPE getOvPlacement() {
123 return _ov_placement;
126 final PHYLOGENY_GRAPHICS_TYPE getPhylogenyGraphicsType() {
127 return _phylogeny_graphics_type;
130 final float getPrintLineWidth() {
131 return _print_line_width;
134 final int getPrintSizeX() {
135 return _print_size_x;
138 final int getPrintSizeY() {
139 return _print_size_y;
142 final double getScaleBarLength() {
143 return _scale_bar_length;
146 final private void init() {
147 _default_node_shape = NodeShape.CIRCLE;
148 _default_node_fill = NodeFill.GRADIENT;
149 _default_node_shape_size = Constants.DEFAULT_NODE_SHAPE_SIZE_DEFAULT;
150 _taxonomy_colorize_node_shapes = false;
151 _show_branch_length_values = false;
152 _internal_number_are_confidence_for_nh_parsing = false;
154 _antialias_screen = true;
155 _antialias_print = true;
156 _graphics_export_visible_only = false;
158 _background_color_gradient = false;
159 _show_default_node_shapes = false;
160 if ( AptxUtil.isUsOrCanada() ) {
161 _print_size_x = Constants.US_LETTER_SIZE_X;
162 _print_size_y = Constants.US_LETTER_SIZE_Y;
165 _print_size_x = Constants.A4_SIZE_X;
166 _print_size_y = Constants.A4_SIZE_Y;
168 _min_confidence_value = MIN_CONFIDENCE_DEFAULT;
169 _print_black_and_white = false;
170 _print_using_actual_size = false;
171 _graphics_export_using_actual_size = true;
172 _phylogeny_graphics_type = PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR;
173 _base_font = new Font( Configuration.getDefaultFontFamilyName(), Font.PLAIN, 10 );
174 _match_whole_terms_only = false;
175 _search_case_sensitive = false;
176 _print_line_width = Constants.PDF_LINE_WIDTH_DEFAULT;
177 _show_overview = true;
178 _ov_placement = OVERVIEW_PLACEMENT_TYPE.UPPER_LEFT;
179 _node_label_direction = NODE_LABEL_DIRECTION.HORIZONTAL;
180 _inverse_search_result = false;
181 _scale_bar_length = 0.0;
182 _number_of_digits_after_comma_for_branch_length_values = Constants.NUMBER_OF_DIGITS_AFTER_COMMA_FOR_BRANCH_LENGTH_VALUES_DEFAULT;
183 _number_of_digits_after_comma_for_confidence_values = Constants.NUMBER_OF_DIGITS_AFTER_COMMA_FOR_CONFIDENCE_VALUES_DEFAULT;
184 _nh_parsing_replace_underscores = false;
185 _nh_parsing_extract_pfam_taxonomy_codes = false;
186 _cladogram_type = Constants.CLADOGRAM_TYPE_DEFAULT;
187 _show_domain_labels = true;
188 setAbbreviateScientificTaxonNames( false );
189 _color_labels_same_as_parent_branch = false;
190 _show_confidence_stddev = true;
191 _nh_conversion_support_value_style = NH_CONVERSION_SUPPORT_VALUE_STYLE.NONE;
194 boolean isShowConfidenceStddev() {
195 return _show_confidence_stddev;
198 void setShowConfidenceStddev( final boolean show_confidence_stddev ) {
199 _show_confidence_stddev = show_confidence_stddev;
202 NH_CONVERSION_SUPPORT_VALUE_STYLE getNhConversionSupportValueStyle() {
203 return _nh_conversion_support_value_style;
206 void setNhConversionSupportValueStyle( final NH_CONVERSION_SUPPORT_VALUE_STYLE nh_conversion_support_value_style ) {
207 _nh_conversion_support_value_style = nh_conversion_support_value_style;
210 final boolean isAbbreviateScientificTaxonNames() {
211 return _abbreviate_scientific_names;
214 boolean isAllowMagnificationOfTaxonomyImages() {
218 final boolean isAntialiasPrint() {
219 return _antialias_print;
222 final boolean isAntialiasScreen() {
223 return _antialias_screen;
226 final boolean isBackgroundColorGradient() {
227 return _background_color_gradient;
230 final boolean isColorLabelsSameAsParentBranch() {
231 return _color_labels_same_as_parent_branch;
234 final boolean isEditable() {
238 final boolean isExtractPfamTaxonomyCodesInNhParsing() {
239 return _nh_parsing_extract_pfam_taxonomy_codes;
242 final boolean isGraphicsExportUsingActualSize() {
243 return _graphics_export_using_actual_size;
246 final boolean isGraphicsExportVisibleOnly() {
247 return _graphics_export_visible_only;
250 final boolean isInternalNumberAreConfidenceForNhParsing() {
251 return _internal_number_are_confidence_for_nh_parsing;
254 final boolean isInverseSearchResult() {
255 return _inverse_search_result;
258 final boolean isMatchWholeTermsOnly() {
259 return _match_whole_terms_only;
262 final boolean isPrintBlackAndWhite() {
263 return _print_black_and_white;
266 final boolean isPrintUsingActualSize() {
267 return _print_using_actual_size;
270 final boolean isReplaceUnderscoresInNhParsing() {
271 return _nh_parsing_replace_underscores;
274 final boolean isSearchCaseSensitive() {
275 return _search_case_sensitive;
278 final boolean isShowBranchLengthValues() {
279 return _show_branch_length_values;
282 public final boolean isShowDomainLabels() {
283 return _show_domain_labels;
286 final boolean isShowOverview() {
287 return _show_overview;
290 final boolean isShowScale() {
294 boolean isTaxonomyColorizeNodeShapes() {
295 return _taxonomy_colorize_node_shapes;
298 final void setAbbreviateScientificTaxonNames( final boolean abbreviate_scientific_names ) {
299 _abbreviate_scientific_names = abbreviate_scientific_names;
302 final void setAntialiasPrint( final boolean antialias_print ) {
303 _antialias_print = antialias_print;
306 final void setAntialiasScreen( final boolean antialias_screen ) {
307 _antialias_screen = antialias_screen;
310 public void setBackgroundColorGradient( final boolean background_color_gradient ) {
311 _background_color_gradient = background_color_gradient;
314 final void setBaseFont( final Font base_font ) {
315 _base_font = base_font;
318 final void setCladogramType( final CLADOGRAM_TYPE cladogram_type ) {
319 _cladogram_type = cladogram_type;
322 public void setColorLabelsSameAsParentBranch( final boolean color_labels_same_as_parent_branch ) {
323 _color_labels_same_as_parent_branch = color_labels_same_as_parent_branch;
326 final void setDefaultNodeFill( final NodeFill default_node_fill ) {
327 _default_node_fill = default_node_fill;
330 final void setDefaultNodeShape( final NodeShape default_node_shape ) {
331 _default_node_shape = default_node_shape;
334 final void setDefaultNodeShapeSize( final short default_node_shape_size ) {
335 _default_node_shape_size = default_node_shape_size;
338 final void setEditable( final boolean editable ) {
339 _editable = editable;
342 final void setExtractPfamTaxonomyCodesInNhParsing( final boolean nh_parsing_extract_pfam_taxonomy_codes ) {
343 _nh_parsing_extract_pfam_taxonomy_codes = nh_parsing_extract_pfam_taxonomy_codes;
346 final void setGraphicsExportUsingActualSize( final boolean graphics_export_using_actual_size ) {
347 _graphics_export_using_actual_size = graphics_export_using_actual_size;
348 if ( !graphics_export_using_actual_size ) {
349 setGraphicsExportVisibleOnly( false );
353 final void setGraphicsExportVisibleOnly( final boolean graphics_export_visible_only ) {
354 _graphics_export_visible_only = graphics_export_visible_only;
355 if ( graphics_export_visible_only ) {
356 setGraphicsExportUsingActualSize( true );
360 final void setInternalNumberAreConfidenceForNhParsing( final boolean internal_number_are_confidence_for_nh_parsing ) {
361 _internal_number_are_confidence_for_nh_parsing = internal_number_are_confidence_for_nh_parsing;
364 final void setInverseSearchResult( final boolean inverse_search_result ) {
365 _inverse_search_result = inverse_search_result;
368 final void setMatchWholeTermsOnly( final boolean search_whole_words_only ) {
369 _match_whole_terms_only = search_whole_words_only;
372 final void setMinConfidenceValue( final double min_confidence_value ) {
373 _min_confidence_value = min_confidence_value;
376 final void setNodeLabelDirection( final NODE_LABEL_DIRECTION node_label_direction ) {
377 _node_label_direction = node_label_direction;
380 final private void setNumberOfDigitsAfterCommaForBranchLength( final short number_of_digits_after_comma_for_branch_length_values ) {
381 _number_of_digits_after_comma_for_branch_length_values = number_of_digits_after_comma_for_branch_length_values;
384 final private void setNumberOfDigitsAfterCommaForConfidenceValues( final short number_of_digits_after_comma_for_confidence_values ) {
385 _number_of_digits_after_comma_for_confidence_values = number_of_digits_after_comma_for_confidence_values;
388 final void setOvPlacement( final OVERVIEW_PLACEMENT_TYPE ov_placement ) {
389 _ov_placement = ov_placement;
392 final void setPhylogenyGraphicsType( final PHYLOGENY_GRAPHICS_TYPE phylogeny_graphics_type ) {
393 _phylogeny_graphics_type = phylogeny_graphics_type;
396 final void setPrintBlackAndWhite( final boolean print_black_and_white ) {
397 _print_black_and_white = print_black_and_white;
400 final void setPrintLineWidth( final float print_line_width ) {
401 _print_line_width = print_line_width;
404 final void setPrintSizeX( final int print_size_x ) {
405 _print_size_x = print_size_x;
408 final void setPrintSizeY( final int print_size_y ) {
409 _print_size_y = print_size_y;
412 final void setPrintUsingActualSize( final boolean print_using_actual_size ) {
413 _print_using_actual_size = print_using_actual_size;
416 final void setReplaceUnderscoresInNhParsing( final boolean nh_parsing_replace_underscores ) {
417 _nh_parsing_replace_underscores = nh_parsing_replace_underscores;
420 final void setScaleBarLength( final double scale_bar_length ) {
421 _scale_bar_length = scale_bar_length;
424 final void setSearchCaseSensitive( final boolean search_case_sensitive ) {
425 _search_case_sensitive = search_case_sensitive;
428 final void setShowBranchLengthValues( final boolean show_branch_length_values ) {
429 _show_branch_length_values = show_branch_length_values;
432 public void setShowDomainLabels( final boolean show_domain_labels ) {
433 _show_domain_labels = show_domain_labels;
436 final void setShowOverview( final boolean show_overview ) {
437 _show_overview = show_overview;
440 final void setShowScale( final boolean show_scale ) {
441 _show_scale = show_scale;
444 void setTaxonomyColorizeNodeShapes( final boolean taxonomy_colorize_node_shapes ) {
445 _taxonomy_colorize_node_shapes = taxonomy_colorize_node_shapes;
448 final static Options createDefaultInstance() {
449 return new Options();
452 boolean isShowDefaultNodeShapes() {
453 return _show_default_node_shapes;
456 void setShowDefaultNodeShapes( final boolean show_default_node_shapes ) {
457 _show_default_node_shapes = show_default_node_shapes;
460 public final static Options createInstance( final Configuration configuration ) {
461 final Options instance = createDefaultInstance();
462 if ( configuration != null ) {
463 instance.setAntialiasScreen( configuration.isAntialiasScreen() );
464 instance.setShowScale( configuration.isShowScale() );
465 instance.setShowBranchLengthValues( configuration.isShowBranchLengthValues() );
466 instance.setShowOverview( configuration.isShowOverview() );
467 instance.setCladogramType( configuration.getCladogramType() );
468 instance.setOvPlacement( configuration.getOvPlacement() );
469 instance.setPrintLineWidth( configuration.getPrintLineWidth() );
470 instance.setNodeLabelDirection( configuration.getNodeLabelDirection() );
471 instance.setBackgroundColorGradient( configuration.isBackgroundColorGradient() );
472 if ( configuration.getNumberOfDigitsAfterCommaForBranchLengthValues() >= 0 ) {
473 instance.setNumberOfDigitsAfterCommaForBranchLength( configuration
474 .getNumberOfDigitsAfterCommaForBranchLengthValues() );
476 if ( configuration.getNumberOfDigitsAfterCommaForConfidenceValues() >= 0 ) {
477 instance.setNumberOfDigitsAfterCommaForConfidenceValues( configuration
478 .getNumberOfDigitsAfterCommaForConfidenceValues() );
480 instance.setExtractPfamTaxonomyCodesInNhParsing( configuration.isExtractPfamTaxonomyCodesInNhParsing() );
481 instance.setReplaceUnderscoresInNhParsing( configuration.isReplaceUnderscoresInNhParsing() );
482 instance.setInternalNumberAreConfidenceForNhParsing( configuration
483 .isInternalNumberAreConfidenceForNhParsing() );
484 instance.setEditable( configuration.isEditable() );
485 instance.setColorLabelsSameAsParentBranch( configuration.isColorLabelsSameAsParentBranch() );
486 instance.setShowDomainLabels( configuration.isShowDomainLabels() );
487 instance.setAbbreviateScientificTaxonNames( configuration.isAbbreviateScientificTaxonNames() );
488 if ( configuration.getMinConfidenceValue() != MIN_CONFIDENCE_DEFAULT ) {
489 instance.setMinConfidenceValue( configuration.getMinConfidenceValue() );
491 if ( configuration.getGraphicsExportX() > 0 ) {
492 instance.setPrintSizeX( configuration.getGraphicsExportX() );
494 if ( configuration.getGraphicsExportY() > 0 ) {
495 instance.setPrintSizeY( configuration.getGraphicsExportY() );
497 if ( configuration.getBaseFontSize() > 0 ) {
498 instance.setBaseFont( instance.getBaseFont().deriveFont( ( float ) configuration.getBaseFontSize() ) );
500 if ( !ForesterUtil.isEmpty( configuration.getBaseFontFamilyName() ) ) {
501 instance.setBaseFont( new Font( configuration.getBaseFontFamilyName(), Font.PLAIN, instance
502 .getBaseFont().getSize() ) );
504 if ( configuration.getPhylogenyGraphicsType() != null ) {
505 instance.setPhylogenyGraphicsType( configuration.getPhylogenyGraphicsType() );
507 if ( configuration.getDefaultNodeFill() != null ) {
508 instance.setDefaultNodeFill( configuration.getDefaultNodeFill() );
510 if ( configuration.getDefaultNodeShape() != null ) {
511 instance.setDefaultNodeShape( configuration.getDefaultNodeShape() );
513 if ( configuration.getDefaultNodeShapeSize() >= 0 ) {
514 instance.setDefaultNodeShapeSize( configuration.getDefaultNodeShapeSize() );
516 instance.setTaxonomyColorizeNodeShapes( configuration.isTaxonomyColorizeNodeShapes() );
517 instance.setShowDefaultNodeShapes( configuration.isShowDefaultNodeShapes() );
522 public static enum CLADOGRAM_TYPE {
523 NON_LINED_UP, EXT_NODE_SUM_DEP, TOTAL_NODE_SUM_DEP;
526 public static enum NODE_LABEL_DIRECTION {
530 static enum OVERVIEW_PLACEMENT_TYPE {
531 UPPER_LEFT( "upper left" ),
532 UPPER_RIGHT( "upper right" ),
533 LOWER_LEFT( "lower left" ),
534 LOWER_RIGHT( "lower right" );
536 private final String _name;
538 private OVERVIEW_PLACEMENT_TYPE( final String name ) {
543 public String toString() {
547 public String toTag() {
548 return toString().replaceAll( " ", "_" );
552 public static enum PHYLOGENY_GRAPHICS_TYPE {
553 RECTANGULAR, TRIANGULAR, EURO_STYLE, ROUNDED, CONVEX, CURVED, UNROOTED, CIRCULAR;