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.util.ForesterUtil;
33 * This is to hold changeable options.
35 final public class Options {
37 static final double MIN_CONFIDENCE_DEFAULT = 0.0;
38 private boolean _show_branch_length_values;
39 private boolean _internal_number_are_confidence_for_nh_parsing;
40 private boolean _show_scale;
41 private boolean _show_overview;
42 private boolean _antialias_screen;
43 private boolean _antialias_print;
44 private boolean _graphics_export_visible_only;
45 private int _print_size_x;
46 private int _print_size_y;
47 private double _min_confidence_value;
48 private boolean _print_black_and_white;
49 private boolean _print_using_actual_size;
50 private boolean _graphics_export_using_actual_size;
51 private PHYLOGENY_GRAPHICS_TYPE _phylogeny_graphics_type;
52 private CLADOGRAM_TYPE _cladogram_type;
53 private OVERVIEW_PLACEMENT_TYPE _ov_placement;
54 private NODE_LABEL_DIRECTION _node_label_direction;
55 private Font _base_font;
56 private boolean _match_whole_terms_only;
57 private boolean _search_case_sensitive;
58 private float _print_line_width;
59 private boolean _inverse_search_result;
60 private double _scale_bar_length;
61 private short _number_of_digits_after_comma_for_confidence_values;
62 private short _number_of_digits_after_comma_for_branch_length_values;
63 private boolean _nh_parsing_replace_underscores;
64 private boolean _nh_parsing_extract_pfam_taxonomy_codes;
65 private boolean _editable;
66 private boolean _background_color_gradient;
67 private boolean _show_domain_labels;
68 private boolean _color_labels_same_as_parent_branch;
69 private boolean _abbreviate_scientific_names;
70 private NodeShape _default_node_shape;
71 private NodeFill _default_node_fill;
72 private short _default_node_shape_size;
73 private boolean _taxonomy_colorize_node_shapes_instead_of_labels;
79 final Font getBaseFont() {
83 final CLADOGRAM_TYPE getCladogramType() {
84 return _cladogram_type;
87 int getDefaultNodeBoxSize() {
88 // TODO make variable ~~
92 final NodeFill getDefaultNodeFill() {
93 return _default_node_fill;
96 final NodeShape getDefaultNodeShape() {
97 return _default_node_shape;
100 final short getDefaultNodeShapeSize() {
101 return _default_node_shape_size;
104 final double getMinConfidenceValue() {
105 return _min_confidence_value;
108 final NODE_LABEL_DIRECTION getNodeLabelDirection() {
109 return _node_label_direction;
112 final short getNumberOfDigitsAfterCommaForBranchLengthValues() {
113 return _number_of_digits_after_comma_for_branch_length_values;
116 final short getNumberOfDigitsAfterCommaForConfidenceValues() {
117 return _number_of_digits_after_comma_for_confidence_values;
120 final OVERVIEW_PLACEMENT_TYPE getOvPlacement() {
121 return _ov_placement;
124 final PHYLOGENY_GRAPHICS_TYPE getPhylogenyGraphicsType() {
125 return _phylogeny_graphics_type;
128 final float getPrintLineWidth() {
129 return _print_line_width;
132 final int getPrintSizeX() {
133 return _print_size_x;
136 final int getPrintSizeY() {
137 return _print_size_y;
140 final double getScaleBarLength() {
141 return _scale_bar_length;
144 final private void init() {
145 _default_node_shape = NodeShape.NONE;
146 _default_node_fill = NodeFill.GRADIENT;
147 _default_node_shape_size = Constants.DEFAULT_NODE_SHAPE_SIZE_DEFAULT;
148 _taxonomy_colorize_node_shapes_instead_of_labels = false;
149 _show_branch_length_values = false;
150 _internal_number_are_confidence_for_nh_parsing = false;
152 _antialias_screen = true;
153 _antialias_print = true;
154 _graphics_export_visible_only = false;
156 _background_color_gradient = 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 isTaxonomyColorizeNodeShapesInsteadOfLabels() {
274 return _taxonomy_colorize_node_shapes_instead_of_labels;
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 setTaxonomyColorizeNodeShapesInsteadOfLabels( final boolean taxonomy_colorize_node_shapes_instead_of_labels ) {
424 _taxonomy_colorize_node_shapes_instead_of_labels = taxonomy_colorize_node_shapes_instead_of_labels;
427 final static Options createDefaultInstance() {
428 return new Options();
431 final static Options createInstance( final Configuration configuration ) {
432 final Options instance = createDefaultInstance();
433 if ( configuration != null ) {
434 instance.setAntialiasScreen( configuration.isAntialiasScreen() );
435 instance.setShowScale( configuration.isShowScale() );
436 instance.setShowBranchLengthValues( configuration.isShowBranchLengthValues() );
437 instance.setShowOverview( configuration.isShowOverview() );
438 instance.setCladogramType( configuration.getCladogramType() );
439 instance.setOvPlacement( configuration.getOvPlacement() );
440 instance.setPrintLineWidth( configuration.getPrintLineWidth() );
441 instance.setNodeLabelDirection( configuration.getNodeLabelDirection() );
442 instance.setBackgroundColorGradient( configuration.isBackgroundColorGradient() );
443 if ( configuration.getNumberOfDigitsAfterCommaForBranchLengthValues() >= 0 ) {
444 instance.setNumberOfDigitsAfterCommaForBranchLength( configuration
445 .getNumberOfDigitsAfterCommaForBranchLengthValues() );
447 if ( configuration.getNumberOfDigitsAfterCommaForConfidenceValues() >= 0 ) {
448 instance.setNumberOfDigitsAfterCommaForConfidenceValues( configuration
449 .getNumberOfDigitsAfterCommaForConfidenceValues() );
451 instance.setExtractPfamTaxonomyCodesInNhParsing( configuration.isExtractPfamTaxonomyCodesInNhParsing() );
452 instance.setReplaceUnderscoresInNhParsing( configuration.isReplaceUnderscoresInNhParsing() );
453 instance.setInternalNumberAreConfidenceForNhParsing( configuration
454 .isInternalNumberAreConfidenceForNhParsing() );
455 instance.setEditable( configuration.isEditable() );
456 instance.setColorLabelsSameAsParentBranch( configuration.isColorLabelsSameAsParentBranch() );
457 instance.setShowDomainLabels( configuration.isShowDomainLabels() );
458 instance.setAbbreviateScientificTaxonNames( configuration.isAbbreviateScientificTaxonNames() );
459 if ( configuration.getMinConfidenceValue() != MIN_CONFIDENCE_DEFAULT ) {
460 instance.setMinConfidenceValue( configuration.getMinConfidenceValue() );
462 if ( configuration.getGraphicsExportX() > 0 ) {
463 instance.setPrintSizeX( configuration.getGraphicsExportX() );
465 if ( configuration.getGraphicsExportY() > 0 ) {
466 instance.setPrintSizeY( configuration.getGraphicsExportY() );
468 if ( configuration.getBaseFontSize() > 0 ) {
469 instance.setBaseFont( instance.getBaseFont().deriveFont( ( float ) configuration.getBaseFontSize() ) );
471 if ( !ForesterUtil.isEmpty( configuration.getBaseFontFamilyName() ) ) {
472 instance.setBaseFont( new Font( configuration.getBaseFontFamilyName(), Font.PLAIN, instance
473 .getBaseFont().getSize() ) );
475 if ( configuration.getPhylogenyGraphicsType() != null ) {
476 instance.setPhylogenyGraphicsType( configuration.getPhylogenyGraphicsType() );
478 if ( configuration.getDefaultNodeFill() != null ) {
479 instance.setDefaultNodeFill( configuration.getDefaultNodeFill() );
481 if ( configuration.getDefaultNodeShape() != null ) {
482 instance.setDefaultNodeShape( configuration.getDefaultNodeShape() );
484 if ( configuration.getDefaultNodeShapeSize() >= 0 ) {
485 instance.setDefaultNodeShapeSize( configuration.getDefaultNodeShapeSize() );
487 instance.setTaxonomyColorizeNodeShapesInsteadOfLabels( configuration
488 .isTaxonomyColorizeNodeShapesInsteadOfLabels() );
493 static enum CLADOGRAM_TYPE {
494 NON_LINED_UP, EXT_NODE_SUM_DEP, TOTAL_NODE_SUM_DEP;
497 static enum NODE_LABEL_DIRECTION {
502 NONE, GRADIENT, SOLID
506 NONE, CIRCLE, RECTANGLE
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;