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;
83 final Font getBaseFont() {
87 final CLADOGRAM_TYPE getCladogramType() {
88 return _cladogram_type;
91 final NodeFill getDefaultNodeFill() {
92 return _default_node_fill;
95 final NodeShape getDefaultNodeShape() {
96 return _default_node_shape;
99 final short getDefaultNodeShapeSize() {
100 return _default_node_shape_size;
103 final double getMinConfidenceValue() {
104 return _min_confidence_value;
107 final NODE_LABEL_DIRECTION getNodeLabelDirection() {
108 return _node_label_direction;
111 final short getNumberOfDigitsAfterCommaForBranchLengthValues() {
112 return _number_of_digits_after_comma_for_branch_length_values;
115 final short getNumberOfDigitsAfterCommaForConfidenceValues() {
116 return _number_of_digits_after_comma_for_confidence_values;
119 final OVERVIEW_PLACEMENT_TYPE getOvPlacement() {
120 return _ov_placement;
123 final PHYLOGENY_GRAPHICS_TYPE getPhylogenyGraphicsType() {
124 return _phylogeny_graphics_type;
127 final float getPrintLineWidth() {
128 return _print_line_width;
131 final int getPrintSizeX() {
132 return _print_size_x;
135 final int getPrintSizeY() {
136 return _print_size_y;
139 final double getScaleBarLength() {
140 return _scale_bar_length;
143 final private void init() {
144 _default_node_shape = NodeShape.CIRCLE;
145 _default_node_fill = NodeFill.GRADIENT;
146 _default_node_shape_size = Constants.DEFAULT_NODE_SHAPE_SIZE_DEFAULT;
147 _taxonomy_colorize_node_shapes = false;
148 _show_branch_length_values = false;
149 _internal_number_are_confidence_for_nh_parsing = false;
151 _antialias_screen = true;
152 _antialias_print = true;
153 _graphics_export_visible_only = false;
155 _background_color_gradient = false;
156 _show_default_node_shapes = false;
157 if ( Util.isUsOrCanada() ) {
158 _print_size_x = Constants.US_LETTER_SIZE_X;
159 _print_size_y = Constants.US_LETTER_SIZE_Y;
162 _print_size_x = Constants.A4_SIZE_X;
163 _print_size_y = Constants.A4_SIZE_Y;
165 _min_confidence_value = MIN_CONFIDENCE_DEFAULT;
166 _print_black_and_white = false;
167 _print_using_actual_size = false;
168 _graphics_export_using_actual_size = true;
169 _phylogeny_graphics_type = PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR;
170 _base_font = new Font( Configuration.getDefaultFontFamilyName(), Font.PLAIN, 10 );
171 _match_whole_terms_only = false;
172 _search_case_sensitive = false;
173 _print_line_width = Constants.PDF_LINE_WIDTH_DEFAULT;
174 _show_overview = true;
175 _ov_placement = OVERVIEW_PLACEMENT_TYPE.UPPER_LEFT;
176 _node_label_direction = NODE_LABEL_DIRECTION.HORIZONTAL;
177 _inverse_search_result = false;
178 _scale_bar_length = 0.0;
179 _number_of_digits_after_comma_for_branch_length_values = Constants.NUMBER_OF_DIGITS_AFTER_COMMA_FOR_BRANCH_LENGTH_VALUES_DEFAULT;
180 _number_of_digits_after_comma_for_confidence_values = Constants.NUMBER_OF_DIGITS_AFTER_COMMA_FOR_CONFIDENCE_VALUES_DEFAULT;
181 _nh_parsing_replace_underscores = false;
182 _nh_parsing_extract_pfam_taxonomy_codes = false;
183 _cladogram_type = Constants.CLADOGRAM_TYPE_DEFAULT;
184 _show_domain_labels = true;
185 setAbbreviateScientificTaxonNames( false );
186 _color_labels_same_as_parent_branch = false;
189 final boolean isAbbreviateScientificTaxonNames() {
190 return _abbreviate_scientific_names;
193 boolean isAllowMagnificationOfTaxonomyImages() {
197 final boolean isAntialiasPrint() {
198 return _antialias_print;
201 final boolean isAntialiasScreen() {
202 return _antialias_screen;
205 final boolean isBackgroundColorGradient() {
206 return _background_color_gradient;
209 final boolean isColorLabelsSameAsParentBranch() {
210 return _color_labels_same_as_parent_branch;
213 final boolean isEditable() {
217 final boolean isExtractPfamTaxonomyCodesInNhParsing() {
218 return _nh_parsing_extract_pfam_taxonomy_codes;
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 public final boolean isShowDomainLabels() {
262 return _show_domain_labels;
265 final boolean isShowOverview() {
266 return _show_overview;
269 final boolean isShowScale() {
273 boolean isTaxonomyColorizeNodeShapes() {
274 return _taxonomy_colorize_node_shapes;
277 final void setAbbreviateScientificTaxonNames( final boolean abbreviate_scientific_names ) {
278 _abbreviate_scientific_names = abbreviate_scientific_names;
281 final void setAntialiasPrint( final boolean antialias_print ) {
282 _antialias_print = antialias_print;
285 final void setAntialiasScreen( final boolean antialias_screen ) {
286 _antialias_screen = antialias_screen;
289 public void setBackgroundColorGradient( final boolean background_color_gradient ) {
290 _background_color_gradient = background_color_gradient;
293 final void setBaseFont( final Font base_font ) {
294 _base_font = base_font;
297 final void setCladogramType( final CLADOGRAM_TYPE cladogram_type ) {
298 _cladogram_type = cladogram_type;
301 public void setColorLabelsSameAsParentBranch( final boolean color_labels_same_as_parent_branch ) {
302 _color_labels_same_as_parent_branch = color_labels_same_as_parent_branch;
305 final void setDefaultNodeFill( final NodeFill default_node_fill ) {
306 _default_node_fill = default_node_fill;
309 final void setDefaultNodeShape( final NodeShape default_node_shape ) {
310 _default_node_shape = default_node_shape;
313 final void setDefaultNodeShapeSize( final short default_node_shape_size ) {
314 _default_node_shape_size = default_node_shape_size;
317 final void setEditable( final boolean editable ) {
318 _editable = editable;
321 final void setExtractPfamTaxonomyCodesInNhParsing( final boolean nh_parsing_extract_pfam_taxonomy_codes ) {
322 _nh_parsing_extract_pfam_taxonomy_codes = nh_parsing_extract_pfam_taxonomy_codes;
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 final void setNodeLabelDirection( final NODE_LABEL_DIRECTION node_label_direction ) {
356 _node_label_direction = node_label_direction;
359 final private void setNumberOfDigitsAfterCommaForBranchLength( final short number_of_digits_after_comma_for_branch_length_values ) {
360 _number_of_digits_after_comma_for_branch_length_values = number_of_digits_after_comma_for_branch_length_values;
363 final private void setNumberOfDigitsAfterCommaForConfidenceValues( final short number_of_digits_after_comma_for_confidence_values ) {
364 _number_of_digits_after_comma_for_confidence_values = number_of_digits_after_comma_for_confidence_values;
367 final void setOvPlacement( final OVERVIEW_PLACEMENT_TYPE ov_placement ) {
368 _ov_placement = ov_placement;
371 final void setPhylogenyGraphicsType( final PHYLOGENY_GRAPHICS_TYPE phylogeny_graphics_type ) {
372 _phylogeny_graphics_type = phylogeny_graphics_type;
375 final void setPrintBlackAndWhite( final boolean print_black_and_white ) {
376 _print_black_and_white = print_black_and_white;
379 final void setPrintLineWidth( final float print_line_width ) {
380 _print_line_width = print_line_width;
383 final void setPrintSizeX( final int print_size_x ) {
384 _print_size_x = print_size_x;
387 final void setPrintSizeY( final int print_size_y ) {
388 _print_size_y = print_size_y;
391 final void setPrintUsingActualSize( final boolean print_using_actual_size ) {
392 _print_using_actual_size = print_using_actual_size;
395 final void setReplaceUnderscoresInNhParsing( final boolean nh_parsing_replace_underscores ) {
396 _nh_parsing_replace_underscores = nh_parsing_replace_underscores;
399 final void setScaleBarLength( final double scale_bar_length ) {
400 _scale_bar_length = scale_bar_length;
403 final void setSearchCaseSensitive( final boolean search_case_sensitive ) {
404 _search_case_sensitive = search_case_sensitive;
407 final void setShowBranchLengthValues( final boolean show_branch_length_values ) {
408 _show_branch_length_values = show_branch_length_values;
411 public void setShowDomainLabels( final boolean show_domain_labels ) {
412 _show_domain_labels = show_domain_labels;
415 final void setShowOverview( final boolean show_overview ) {
416 _show_overview = show_overview;
419 final void setShowScale( final boolean show_scale ) {
420 _show_scale = show_scale;
423 void setTaxonomyColorizeNodeShapes( final boolean taxonomy_colorize_node_shapes ) {
424 _taxonomy_colorize_node_shapes = taxonomy_colorize_node_shapes;
427 final static Options createDefaultInstance() {
428 return new Options();
431 boolean isShowDefaultNodeShapes() {
432 return _show_default_node_shapes;
435 void setShowDefaultNodeShapes( final boolean show_default_node_shapes ) {
436 _show_default_node_shapes = show_default_node_shapes;
439 public final static Options createInstance( final Configuration configuration ) {
440 final Options instance = createDefaultInstance();
441 if ( configuration != null ) {
442 instance.setAntialiasScreen( configuration.isAntialiasScreen() );
443 instance.setShowScale( configuration.isShowScale() );
444 instance.setShowBranchLengthValues( configuration.isShowBranchLengthValues() );
445 instance.setShowOverview( configuration.isShowOverview() );
446 instance.setCladogramType( configuration.getCladogramType() );
447 instance.setOvPlacement( configuration.getOvPlacement() );
448 instance.setPrintLineWidth( configuration.getPrintLineWidth() );
449 instance.setNodeLabelDirection( configuration.getNodeLabelDirection() );
450 instance.setBackgroundColorGradient( configuration.isBackgroundColorGradient() );
451 if ( configuration.getNumberOfDigitsAfterCommaForBranchLengthValues() >= 0 ) {
452 instance.setNumberOfDigitsAfterCommaForBranchLength( configuration
453 .getNumberOfDigitsAfterCommaForBranchLengthValues() );
455 if ( configuration.getNumberOfDigitsAfterCommaForConfidenceValues() >= 0 ) {
456 instance.setNumberOfDigitsAfterCommaForConfidenceValues( configuration
457 .getNumberOfDigitsAfterCommaForConfidenceValues() );
459 instance.setExtractPfamTaxonomyCodesInNhParsing( configuration.isExtractPfamTaxonomyCodesInNhParsing() );
460 instance.setReplaceUnderscoresInNhParsing( configuration.isReplaceUnderscoresInNhParsing() );
461 instance.setInternalNumberAreConfidenceForNhParsing( configuration
462 .isInternalNumberAreConfidenceForNhParsing() );
463 instance.setEditable( configuration.isEditable() );
464 instance.setColorLabelsSameAsParentBranch( configuration.isColorLabelsSameAsParentBranch() );
465 instance.setShowDomainLabels( configuration.isShowDomainLabels() );
466 instance.setAbbreviateScientificTaxonNames( configuration.isAbbreviateScientificTaxonNames() );
467 if ( configuration.getMinConfidenceValue() != MIN_CONFIDENCE_DEFAULT ) {
468 instance.setMinConfidenceValue( configuration.getMinConfidenceValue() );
470 if ( configuration.getGraphicsExportX() > 0 ) {
471 instance.setPrintSizeX( configuration.getGraphicsExportX() );
473 if ( configuration.getGraphicsExportY() > 0 ) {
474 instance.setPrintSizeY( configuration.getGraphicsExportY() );
476 if ( configuration.getBaseFontSize() > 0 ) {
477 instance.setBaseFont( instance.getBaseFont().deriveFont( ( float ) configuration.getBaseFontSize() ) );
479 if ( !ForesterUtil.isEmpty( configuration.getBaseFontFamilyName() ) ) {
480 instance.setBaseFont( new Font( configuration.getBaseFontFamilyName(), Font.PLAIN, instance
481 .getBaseFont().getSize() ) );
483 if ( configuration.getPhylogenyGraphicsType() != null ) {
484 instance.setPhylogenyGraphicsType( configuration.getPhylogenyGraphicsType() );
486 if ( configuration.getDefaultNodeFill() != null ) {
487 instance.setDefaultNodeFill( configuration.getDefaultNodeFill() );
489 if ( configuration.getDefaultNodeShape() != null ) {
490 instance.setDefaultNodeShape( configuration.getDefaultNodeShape() );
492 if ( configuration.getDefaultNodeShapeSize() >= 0 ) {
493 instance.setDefaultNodeShapeSize( configuration.getDefaultNodeShapeSize() );
495 instance.setTaxonomyColorizeNodeShapes( configuration.isTaxonomyColorizeNodeShapes() );
496 instance.setShowDefaultNodeShapes( configuration.isShowDefaultNodeShapes() );
501 static enum CLADOGRAM_TYPE {
502 NON_LINED_UP, EXT_NODE_SUM_DEP, TOTAL_NODE_SUM_DEP;
505 static enum NODE_LABEL_DIRECTION {
509 static enum OVERVIEW_PLACEMENT_TYPE {
510 UPPER_LEFT( "upper left" ),
511 UPPER_RIGHT( "upper right" ),
512 LOWER_LEFT( "lower left" ),
513 LOWER_RIGHT( "lower right" );
515 private final String _name;
517 private OVERVIEW_PLACEMENT_TYPE( final String name ) {
522 public String toString() {
526 public String toTag() {
527 return toString().replaceAll( " ", "_" );
531 static enum PHYLOGENY_GRAPHICS_TYPE {
532 RECTANGULAR, TRIANGULAR, EURO_STYLE, ROUNDED, CONVEX, CURVED, UNROOTED, CIRCULAR;