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.data.NodeVisualization;
31 import org.forester.phylogeny.data.NodeVisualization.NodeFill;
32 import org.forester.phylogeny.data.NodeVisualization.NodeShape;
33 import org.forester.util.ForesterUtil;
36 * This is to hold changeable options.
38 final public class Options {
40 static final double MIN_CONFIDENCE_DEFAULT = 0.0;
41 private boolean _show_branch_length_values;
42 private boolean _internal_number_are_confidence_for_nh_parsing;
43 private boolean _show_scale;
44 private boolean _show_overview;
45 private boolean _antialias_screen;
46 private boolean _antialias_print;
47 private boolean _graphics_export_visible_only;
48 private int _print_size_x;
49 private int _print_size_y;
50 private double _min_confidence_value;
51 private boolean _print_black_and_white;
52 private boolean _print_using_actual_size;
53 private boolean _graphics_export_using_actual_size;
54 private PHYLOGENY_GRAPHICS_TYPE _phylogeny_graphics_type;
55 private CLADOGRAM_TYPE _cladogram_type;
56 private OVERVIEW_PLACEMENT_TYPE _ov_placement;
57 private NODE_LABEL_DIRECTION _node_label_direction;
58 private Font _base_font;
59 private boolean _match_whole_terms_only;
60 private boolean _search_case_sensitive;
61 private float _print_line_width;
62 private boolean _inverse_search_result;
63 private double _scale_bar_length;
64 private short _number_of_digits_after_comma_for_confidence_values;
65 private short _number_of_digits_after_comma_for_branch_length_values;
66 private boolean _nh_parsing_replace_underscores;
67 private boolean _nh_parsing_extract_pfam_taxonomy_codes;
68 private boolean _editable;
69 private boolean _background_color_gradient;
70 private boolean _show_domain_labels;
71 private boolean _color_labels_same_as_parent_branch;
72 private boolean _abbreviate_scientific_names;
73 private NodeVisualization.NodeShape _default_node_shape;
74 private NodeVisualization.NodeFill _default_node_fill;
75 private short _default_node_shape_size;
76 private boolean _taxonomy_colorize_node_shapes;
77 private boolean _show_default_node_shapes;
78 private boolean _show_confidence_stddev;
79 private boolean _use_brackets_for_conf_in_nh_export;
85 final Font getBaseFont() {
89 final CLADOGRAM_TYPE getCladogramType() {
90 return _cladogram_type;
93 final NodeFill getDefaultNodeFill() {
94 return _default_node_fill;
97 final NodeShape getDefaultNodeShape() {
98 return _default_node_shape;
101 final short getDefaultNodeShapeSize() {
102 return _default_node_shape_size;
105 final double getMinConfidenceValue() {
106 return _min_confidence_value;
109 final NODE_LABEL_DIRECTION getNodeLabelDirection() {
110 return _node_label_direction;
113 final short getNumberOfDigitsAfterCommaForBranchLengthValues() {
114 return _number_of_digits_after_comma_for_branch_length_values;
117 final short getNumberOfDigitsAfterCommaForConfidenceValues() {
118 return _number_of_digits_after_comma_for_confidence_values;
121 final OVERVIEW_PLACEMENT_TYPE getOvPlacement() {
122 return _ov_placement;
125 final PHYLOGENY_GRAPHICS_TYPE getPhylogenyGraphicsType() {
126 return _phylogeny_graphics_type;
129 final float getPrintLineWidth() {
130 return _print_line_width;
133 final int getPrintSizeX() {
134 return _print_size_x;
137 final int getPrintSizeY() {
138 return _print_size_y;
141 final double getScaleBarLength() {
142 return _scale_bar_length;
145 final private void init() {
146 _default_node_shape = NodeShape.CIRCLE;
147 _default_node_fill = NodeFill.GRADIENT;
148 _default_node_shape_size = Constants.DEFAULT_NODE_SHAPE_SIZE_DEFAULT;
149 _taxonomy_colorize_node_shapes = false;
150 _show_branch_length_values = false;
151 _internal_number_are_confidence_for_nh_parsing = false;
153 _antialias_screen = true;
154 _antialias_print = true;
155 _graphics_export_visible_only = false;
157 _background_color_gradient = false;
158 _show_default_node_shapes = false;
159 if ( AptxUtil.isUsOrCanada() ) {
160 _print_size_x = Constants.US_LETTER_SIZE_X;
161 _print_size_y = Constants.US_LETTER_SIZE_Y;
164 _print_size_x = Constants.A4_SIZE_X;
165 _print_size_y = Constants.A4_SIZE_Y;
167 _min_confidence_value = MIN_CONFIDENCE_DEFAULT;
168 _print_black_and_white = false;
169 _print_using_actual_size = false;
170 _graphics_export_using_actual_size = true;
171 _phylogeny_graphics_type = PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR;
172 _base_font = new Font( Configuration.getDefaultFontFamilyName(), Font.PLAIN, 10 );
173 _match_whole_terms_only = false;
174 _search_case_sensitive = false;
175 _print_line_width = Constants.PDF_LINE_WIDTH_DEFAULT;
176 _show_overview = true;
177 _ov_placement = OVERVIEW_PLACEMENT_TYPE.UPPER_LEFT;
178 _node_label_direction = NODE_LABEL_DIRECTION.HORIZONTAL;
179 _inverse_search_result = false;
180 _scale_bar_length = 0.0;
181 _number_of_digits_after_comma_for_branch_length_values = Constants.NUMBER_OF_DIGITS_AFTER_COMMA_FOR_BRANCH_LENGTH_VALUES_DEFAULT;
182 _number_of_digits_after_comma_for_confidence_values = Constants.NUMBER_OF_DIGITS_AFTER_COMMA_FOR_CONFIDENCE_VALUES_DEFAULT;
183 _nh_parsing_replace_underscores = false;
184 _nh_parsing_extract_pfam_taxonomy_codes = false;
185 _cladogram_type = Constants.CLADOGRAM_TYPE_DEFAULT;
186 _show_domain_labels = true;
187 setAbbreviateScientificTaxonNames( false );
188 _color_labels_same_as_parent_branch = false;
189 _show_confidence_stddev = true;
190 _use_brackets_for_conf_in_nh_export = false;
193 boolean isShowConfidenceStddev() {
194 return _show_confidence_stddev;
197 void setShowConfidenceStddev( final boolean show_confidence_stddev ) {
198 _show_confidence_stddev = show_confidence_stddev;
201 boolean isUseBracketsForConfInNhExport() {
202 return _use_brackets_for_conf_in_nh_export;
205 void setUseBracketsForConfInNhExport( final boolean use_brackets_for_conf_in_nh_export ) {
206 _use_brackets_for_conf_in_nh_export = use_brackets_for_conf_in_nh_export;
209 final boolean isAbbreviateScientificTaxonNames() {
210 return _abbreviate_scientific_names;
213 boolean isAllowMagnificationOfTaxonomyImages() {
217 final boolean isAntialiasPrint() {
218 return _antialias_print;
221 final boolean isAntialiasScreen() {
222 return _antialias_screen;
225 final boolean isBackgroundColorGradient() {
226 return _background_color_gradient;
229 final boolean isColorLabelsSameAsParentBranch() {
230 return _color_labels_same_as_parent_branch;
233 final boolean isEditable() {
237 final boolean isExtractPfamTaxonomyCodesInNhParsing() {
238 return _nh_parsing_extract_pfam_taxonomy_codes;
241 final boolean isGraphicsExportUsingActualSize() {
242 return _graphics_export_using_actual_size;
245 final boolean isGraphicsExportVisibleOnly() {
246 return _graphics_export_visible_only;
249 final boolean isInternalNumberAreConfidenceForNhParsing() {
250 return _internal_number_are_confidence_for_nh_parsing;
253 final boolean isInverseSearchResult() {
254 return _inverse_search_result;
257 final boolean isMatchWholeTermsOnly() {
258 return _match_whole_terms_only;
261 final boolean isPrintBlackAndWhite() {
262 return _print_black_and_white;
265 final boolean isPrintUsingActualSize() {
266 return _print_using_actual_size;
269 final boolean isReplaceUnderscoresInNhParsing() {
270 return _nh_parsing_replace_underscores;
273 final boolean isSearchCaseSensitive() {
274 return _search_case_sensitive;
277 final boolean isShowBranchLengthValues() {
278 return _show_branch_length_values;
281 public final boolean isShowDomainLabels() {
282 return _show_domain_labels;
285 final boolean isShowOverview() {
286 return _show_overview;
289 final boolean isShowScale() {
293 boolean isTaxonomyColorizeNodeShapes() {
294 return _taxonomy_colorize_node_shapes;
297 final void setAbbreviateScientificTaxonNames( final boolean abbreviate_scientific_names ) {
298 _abbreviate_scientific_names = abbreviate_scientific_names;
301 final void setAntialiasPrint( final boolean antialias_print ) {
302 _antialias_print = antialias_print;
305 final void setAntialiasScreen( final boolean antialias_screen ) {
306 _antialias_screen = antialias_screen;
309 public void setBackgroundColorGradient( final boolean background_color_gradient ) {
310 _background_color_gradient = background_color_gradient;
313 final void setBaseFont( final Font base_font ) {
314 _base_font = base_font;
317 final void setCladogramType( final CLADOGRAM_TYPE cladogram_type ) {
318 _cladogram_type = cladogram_type;
321 public void setColorLabelsSameAsParentBranch( final boolean color_labels_same_as_parent_branch ) {
322 _color_labels_same_as_parent_branch = color_labels_same_as_parent_branch;
325 final void setDefaultNodeFill( final NodeFill default_node_fill ) {
326 _default_node_fill = default_node_fill;
329 final void setDefaultNodeShape( final NodeShape default_node_shape ) {
330 _default_node_shape = default_node_shape;
333 final void setDefaultNodeShapeSize( final short default_node_shape_size ) {
334 _default_node_shape_size = default_node_shape_size;
337 final void setEditable( final boolean editable ) {
338 _editable = editable;
341 final void setExtractPfamTaxonomyCodesInNhParsing( final boolean nh_parsing_extract_pfam_taxonomy_codes ) {
342 _nh_parsing_extract_pfam_taxonomy_codes = nh_parsing_extract_pfam_taxonomy_codes;
345 final void setGraphicsExportUsingActualSize( final boolean graphics_export_using_actual_size ) {
346 _graphics_export_using_actual_size = graphics_export_using_actual_size;
347 if ( !graphics_export_using_actual_size ) {
348 setGraphicsExportVisibleOnly( false );
352 final void setGraphicsExportVisibleOnly( final boolean graphics_export_visible_only ) {
353 _graphics_export_visible_only = graphics_export_visible_only;
354 if ( graphics_export_visible_only ) {
355 setGraphicsExportUsingActualSize( true );
359 final void setInternalNumberAreConfidenceForNhParsing( final boolean internal_number_are_confidence_for_nh_parsing ) {
360 _internal_number_are_confidence_for_nh_parsing = internal_number_are_confidence_for_nh_parsing;
363 final void setInverseSearchResult( final boolean inverse_search_result ) {
364 _inverse_search_result = inverse_search_result;
367 final void setMatchWholeTermsOnly( final boolean search_whole_words_only ) {
368 _match_whole_terms_only = search_whole_words_only;
371 final void setMinConfidenceValue( final double min_confidence_value ) {
372 _min_confidence_value = min_confidence_value;
375 final void setNodeLabelDirection( final NODE_LABEL_DIRECTION node_label_direction ) {
376 _node_label_direction = node_label_direction;
379 final private void setNumberOfDigitsAfterCommaForBranchLength( final short number_of_digits_after_comma_for_branch_length_values ) {
380 _number_of_digits_after_comma_for_branch_length_values = number_of_digits_after_comma_for_branch_length_values;
383 final private void setNumberOfDigitsAfterCommaForConfidenceValues( final short number_of_digits_after_comma_for_confidence_values ) {
384 _number_of_digits_after_comma_for_confidence_values = number_of_digits_after_comma_for_confidence_values;
387 final void setOvPlacement( final OVERVIEW_PLACEMENT_TYPE ov_placement ) {
388 _ov_placement = ov_placement;
391 final void setPhylogenyGraphicsType( final PHYLOGENY_GRAPHICS_TYPE phylogeny_graphics_type ) {
392 _phylogeny_graphics_type = phylogeny_graphics_type;
395 final void setPrintBlackAndWhite( final boolean print_black_and_white ) {
396 _print_black_and_white = print_black_and_white;
399 final void setPrintLineWidth( final float print_line_width ) {
400 _print_line_width = print_line_width;
403 final void setPrintSizeX( final int print_size_x ) {
404 _print_size_x = print_size_x;
407 final void setPrintSizeY( final int print_size_y ) {
408 _print_size_y = print_size_y;
411 final void setPrintUsingActualSize( final boolean print_using_actual_size ) {
412 _print_using_actual_size = print_using_actual_size;
415 final void setReplaceUnderscoresInNhParsing( final boolean nh_parsing_replace_underscores ) {
416 _nh_parsing_replace_underscores = nh_parsing_replace_underscores;
419 final void setScaleBarLength( final double scale_bar_length ) {
420 _scale_bar_length = scale_bar_length;
423 final void setSearchCaseSensitive( final boolean search_case_sensitive ) {
424 _search_case_sensitive = search_case_sensitive;
427 final void setShowBranchLengthValues( final boolean show_branch_length_values ) {
428 _show_branch_length_values = show_branch_length_values;
431 public void setShowDomainLabels( final boolean show_domain_labels ) {
432 _show_domain_labels = show_domain_labels;
435 final void setShowOverview( final boolean show_overview ) {
436 _show_overview = show_overview;
439 final void setShowScale( final boolean show_scale ) {
440 _show_scale = show_scale;
443 void setTaxonomyColorizeNodeShapes( final boolean taxonomy_colorize_node_shapes ) {
444 _taxonomy_colorize_node_shapes = taxonomy_colorize_node_shapes;
447 final static Options createDefaultInstance() {
448 return new Options();
451 boolean isShowDefaultNodeShapes() {
452 return _show_default_node_shapes;
455 void setShowDefaultNodeShapes( final boolean show_default_node_shapes ) {
456 _show_default_node_shapes = show_default_node_shapes;
459 public final static Options createInstance( final Configuration configuration ) {
460 final Options instance = createDefaultInstance();
461 if ( configuration != null ) {
462 instance.setAntialiasScreen( configuration.isAntialiasScreen() );
463 instance.setShowScale( configuration.isShowScale() );
464 instance.setShowBranchLengthValues( configuration.isShowBranchLengthValues() );
465 instance.setShowOverview( configuration.isShowOverview() );
466 instance.setCladogramType( configuration.getCladogramType() );
467 instance.setOvPlacement( configuration.getOvPlacement() );
468 instance.setPrintLineWidth( configuration.getPrintLineWidth() );
469 instance.setNodeLabelDirection( configuration.getNodeLabelDirection() );
470 instance.setBackgroundColorGradient( configuration.isBackgroundColorGradient() );
471 if ( configuration.getNumberOfDigitsAfterCommaForBranchLengthValues() >= 0 ) {
472 instance.setNumberOfDigitsAfterCommaForBranchLength( configuration
473 .getNumberOfDigitsAfterCommaForBranchLengthValues() );
475 if ( configuration.getNumberOfDigitsAfterCommaForConfidenceValues() >= 0 ) {
476 instance.setNumberOfDigitsAfterCommaForConfidenceValues( configuration
477 .getNumberOfDigitsAfterCommaForConfidenceValues() );
479 instance.setExtractPfamTaxonomyCodesInNhParsing( configuration.isExtractPfamTaxonomyCodesInNhParsing() );
480 instance.setReplaceUnderscoresInNhParsing( configuration.isReplaceUnderscoresInNhParsing() );
481 instance.setInternalNumberAreConfidenceForNhParsing( configuration
482 .isInternalNumberAreConfidenceForNhParsing() );
483 instance.setEditable( configuration.isEditable() );
484 instance.setColorLabelsSameAsParentBranch( configuration.isColorLabelsSameAsParentBranch() );
485 instance.setShowDomainLabels( configuration.isShowDomainLabels() );
486 instance.setAbbreviateScientificTaxonNames( configuration.isAbbreviateScientificTaxonNames() );
487 if ( configuration.getMinConfidenceValue() != MIN_CONFIDENCE_DEFAULT ) {
488 instance.setMinConfidenceValue( configuration.getMinConfidenceValue() );
490 if ( configuration.getGraphicsExportX() > 0 ) {
491 instance.setPrintSizeX( configuration.getGraphicsExportX() );
493 if ( configuration.getGraphicsExportY() > 0 ) {
494 instance.setPrintSizeY( configuration.getGraphicsExportY() );
496 if ( configuration.getBaseFontSize() > 0 ) {
497 instance.setBaseFont( instance.getBaseFont().deriveFont( ( float ) configuration.getBaseFontSize() ) );
499 if ( !ForesterUtil.isEmpty( configuration.getBaseFontFamilyName() ) ) {
500 instance.setBaseFont( new Font( configuration.getBaseFontFamilyName(), Font.PLAIN, instance
501 .getBaseFont().getSize() ) );
503 if ( configuration.getPhylogenyGraphicsType() != null ) {
504 instance.setPhylogenyGraphicsType( configuration.getPhylogenyGraphicsType() );
506 if ( configuration.getDefaultNodeFill() != null ) {
507 instance.setDefaultNodeFill( configuration.getDefaultNodeFill() );
509 if ( configuration.getDefaultNodeShape() != null ) {
510 instance.setDefaultNodeShape( configuration.getDefaultNodeShape() );
512 if ( configuration.getDefaultNodeShapeSize() >= 0 ) {
513 instance.setDefaultNodeShapeSize( configuration.getDefaultNodeShapeSize() );
515 instance.setTaxonomyColorizeNodeShapes( configuration.isTaxonomyColorizeNodeShapes() );
516 instance.setShowDefaultNodeShapes( configuration.isShowDefaultNodeShapes() );
521 public static enum CLADOGRAM_TYPE {
522 NON_LINED_UP, EXT_NODE_SUM_DEP, TOTAL_NODE_SUM_DEP;
525 public static enum NODE_LABEL_DIRECTION {
529 static enum OVERVIEW_PLACEMENT_TYPE {
530 UPPER_LEFT( "upper left" ),
531 UPPER_RIGHT( "upper right" ),
532 LOWER_LEFT( "lower left" ),
533 LOWER_RIGHT( "lower right" );
535 private final String _name;
537 private OVERVIEW_PLACEMENT_TYPE( final String name ) {
542 public String toString() {
546 public String toTag() {
547 return toString().replaceAll( " ", "_" );
551 public static enum PHYLOGENY_GRAPHICS_TYPE {
552 RECTANGULAR, TRIANGULAR, EURO_STYLE, ROUNDED, CONVEX, CURVED, UNROOTED, CIRCULAR;