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;
74 private boolean _show_default_node_shapes;
80 final Font getBaseFont() {
84 final CLADOGRAM_TYPE getCladogramType() {
85 return _cladogram_type;
88 final NodeFill getDefaultNodeFill() {
89 return _default_node_fill;
92 final NodeShape getDefaultNodeShape() {
93 return _default_node_shape;
96 final short getDefaultNodeShapeSize() {
97 return _default_node_shape_size;
100 final double getMinConfidenceValue() {
101 return _min_confidence_value;
104 final NODE_LABEL_DIRECTION getNodeLabelDirection() {
105 return _node_label_direction;
108 final short getNumberOfDigitsAfterCommaForBranchLengthValues() {
109 return _number_of_digits_after_comma_for_branch_length_values;
112 final short getNumberOfDigitsAfterCommaForConfidenceValues() {
113 return _number_of_digits_after_comma_for_confidence_values;
116 final OVERVIEW_PLACEMENT_TYPE getOvPlacement() {
117 return _ov_placement;
120 final PHYLOGENY_GRAPHICS_TYPE getPhylogenyGraphicsType() {
121 return _phylogeny_graphics_type;
124 final float getPrintLineWidth() {
125 return _print_line_width;
128 final int getPrintSizeX() {
129 return _print_size_x;
132 final int getPrintSizeY() {
133 return _print_size_y;
136 final double getScaleBarLength() {
137 return _scale_bar_length;
140 final private void init() {
141 _default_node_shape = NodeShape.CIRCLE;
142 _default_node_fill = NodeFill.GRADIENT;
143 _default_node_shape_size = Constants.DEFAULT_NODE_SHAPE_SIZE_DEFAULT;
144 _taxonomy_colorize_node_shapes = false;
145 _show_branch_length_values = false;
146 _internal_number_are_confidence_for_nh_parsing = false;
148 _antialias_screen = true;
149 _antialias_print = true;
150 _graphics_export_visible_only = false;
152 _background_color_gradient = false;
153 _show_default_node_shapes = false;
154 if ( Util.isUsOrCanada() ) {
155 _print_size_x = Constants.US_LETTER_SIZE_X;
156 _print_size_y = Constants.US_LETTER_SIZE_Y;
159 _print_size_x = Constants.A4_SIZE_X;
160 _print_size_y = Constants.A4_SIZE_Y;
162 _min_confidence_value = MIN_CONFIDENCE_DEFAULT;
163 _print_black_and_white = false;
164 _print_using_actual_size = false;
165 _graphics_export_using_actual_size = true;
166 _phylogeny_graphics_type = PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR;
167 _base_font = new Font( Configuration.getDefaultFontFamilyName(), Font.PLAIN, 10 );
168 _match_whole_terms_only = false;
169 _search_case_sensitive = false;
170 _print_line_width = Constants.PDF_LINE_WIDTH_DEFAULT;
171 _show_overview = true;
172 _ov_placement = OVERVIEW_PLACEMENT_TYPE.UPPER_LEFT;
173 _node_label_direction = NODE_LABEL_DIRECTION.HORIZONTAL;
174 _inverse_search_result = false;
175 _scale_bar_length = 0.0;
176 _number_of_digits_after_comma_for_branch_length_values = Constants.NUMBER_OF_DIGITS_AFTER_COMMA_FOR_BRANCH_LENGTH_VALUES_DEFAULT;
177 _number_of_digits_after_comma_for_confidence_values = Constants.NUMBER_OF_DIGITS_AFTER_COMMA_FOR_CONFIDENCE_VALUES_DEFAULT;
178 _nh_parsing_replace_underscores = false;
179 _nh_parsing_extract_pfam_taxonomy_codes = false;
180 _cladogram_type = Constants.CLADOGRAM_TYPE_DEFAULT;
181 _show_domain_labels = true;
182 setAbbreviateScientificTaxonNames( false );
183 _color_labels_same_as_parent_branch = false;
186 final boolean isAbbreviateScientificTaxonNames() {
187 return _abbreviate_scientific_names;
190 boolean isAllowMagnificationOfTaxonomyImages() {
194 final boolean isAntialiasPrint() {
195 return _antialias_print;
198 final boolean isAntialiasScreen() {
199 return _antialias_screen;
202 final boolean isBackgroundColorGradient() {
203 return _background_color_gradient;
206 final boolean isColorLabelsSameAsParentBranch() {
207 return _color_labels_same_as_parent_branch;
210 final boolean isEditable() {
214 final boolean isExtractPfamTaxonomyCodesInNhParsing() {
215 return _nh_parsing_extract_pfam_taxonomy_codes;
218 final boolean isGraphicsExportUsingActualSize() {
219 return _graphics_export_using_actual_size;
222 final boolean isGraphicsExportVisibleOnly() {
223 return _graphics_export_visible_only;
226 final boolean isInternalNumberAreConfidenceForNhParsing() {
227 return _internal_number_are_confidence_for_nh_parsing;
230 final boolean isInverseSearchResult() {
231 return _inverse_search_result;
234 final boolean isMatchWholeTermsOnly() {
235 return _match_whole_terms_only;
238 final boolean isPrintBlackAndWhite() {
239 return _print_black_and_white;
242 final boolean isPrintUsingActualSize() {
243 return _print_using_actual_size;
246 final boolean isReplaceUnderscoresInNhParsing() {
247 return _nh_parsing_replace_underscores;
250 final boolean isSearchCaseSensitive() {
251 return _search_case_sensitive;
254 final boolean isShowBranchLengthValues() {
255 return _show_branch_length_values;
258 public final boolean isShowDomainLabels() {
259 return _show_domain_labels;
262 final boolean isShowOverview() {
263 return _show_overview;
266 final boolean isShowScale() {
270 boolean isTaxonomyColorizeNodeShapes() {
271 return _taxonomy_colorize_node_shapes;
274 final void setAbbreviateScientificTaxonNames( final boolean abbreviate_scientific_names ) {
275 _abbreviate_scientific_names = abbreviate_scientific_names;
278 final void setAntialiasPrint( final boolean antialias_print ) {
279 _antialias_print = antialias_print;
282 final void setAntialiasScreen( final boolean antialias_screen ) {
283 _antialias_screen = antialias_screen;
286 public void setBackgroundColorGradient( final boolean background_color_gradient ) {
287 _background_color_gradient = background_color_gradient;
290 final void setBaseFont( final Font base_font ) {
291 _base_font = base_font;
294 final void setCladogramType( final CLADOGRAM_TYPE cladogram_type ) {
295 _cladogram_type = cladogram_type;
298 public void setColorLabelsSameAsParentBranch( final boolean color_labels_same_as_parent_branch ) {
299 _color_labels_same_as_parent_branch = color_labels_same_as_parent_branch;
302 final void setDefaultNodeFill( final NodeFill default_node_fill ) {
303 _default_node_fill = default_node_fill;
306 final void setDefaultNodeShape( final NodeShape default_node_shape ) {
307 _default_node_shape = default_node_shape;
310 final void setDefaultNodeShapeSize( final short default_node_shape_size ) {
311 _default_node_shape_size = default_node_shape_size;
314 final void setEditable( final boolean editable ) {
315 _editable = editable;
318 final void setExtractPfamTaxonomyCodesInNhParsing( final boolean nh_parsing_extract_pfam_taxonomy_codes ) {
319 _nh_parsing_extract_pfam_taxonomy_codes = nh_parsing_extract_pfam_taxonomy_codes;
322 final void setGraphicsExportUsingActualSize( final boolean graphics_export_using_actual_size ) {
323 _graphics_export_using_actual_size = graphics_export_using_actual_size;
324 if ( !graphics_export_using_actual_size ) {
325 setGraphicsExportVisibleOnly( false );
329 final void setGraphicsExportVisibleOnly( final boolean graphics_export_visible_only ) {
330 _graphics_export_visible_only = graphics_export_visible_only;
331 if ( graphics_export_visible_only ) {
332 setGraphicsExportUsingActualSize( true );
336 final void setInternalNumberAreConfidenceForNhParsing( final boolean internal_number_are_confidence_for_nh_parsing ) {
337 _internal_number_are_confidence_for_nh_parsing = internal_number_are_confidence_for_nh_parsing;
340 final void setInverseSearchResult( final boolean inverse_search_result ) {
341 _inverse_search_result = inverse_search_result;
344 final void setMatchWholeTermsOnly( final boolean search_whole_words_only ) {
345 _match_whole_terms_only = search_whole_words_only;
348 final void setMinConfidenceValue( final double min_confidence_value ) {
349 _min_confidence_value = min_confidence_value;
352 final void setNodeLabelDirection( final NODE_LABEL_DIRECTION node_label_direction ) {
353 _node_label_direction = node_label_direction;
356 final private void setNumberOfDigitsAfterCommaForBranchLength( final short number_of_digits_after_comma_for_branch_length_values ) {
357 _number_of_digits_after_comma_for_branch_length_values = number_of_digits_after_comma_for_branch_length_values;
360 final private void setNumberOfDigitsAfterCommaForConfidenceValues( final short number_of_digits_after_comma_for_confidence_values ) {
361 _number_of_digits_after_comma_for_confidence_values = number_of_digits_after_comma_for_confidence_values;
364 final void setOvPlacement( final OVERVIEW_PLACEMENT_TYPE ov_placement ) {
365 _ov_placement = ov_placement;
368 final void setPhylogenyGraphicsType( final PHYLOGENY_GRAPHICS_TYPE phylogeny_graphics_type ) {
369 _phylogeny_graphics_type = phylogeny_graphics_type;
372 final void setPrintBlackAndWhite( final boolean print_black_and_white ) {
373 _print_black_and_white = print_black_and_white;
376 final void setPrintLineWidth( final float print_line_width ) {
377 _print_line_width = print_line_width;
380 final void setPrintSizeX( final int print_size_x ) {
381 _print_size_x = print_size_x;
384 final void setPrintSizeY( final int print_size_y ) {
385 _print_size_y = print_size_y;
388 final void setPrintUsingActualSize( final boolean print_using_actual_size ) {
389 _print_using_actual_size = print_using_actual_size;
392 final void setReplaceUnderscoresInNhParsing( final boolean nh_parsing_replace_underscores ) {
393 _nh_parsing_replace_underscores = nh_parsing_replace_underscores;
396 final void setScaleBarLength( final double scale_bar_length ) {
397 _scale_bar_length = scale_bar_length;
400 final void setSearchCaseSensitive( final boolean search_case_sensitive ) {
401 _search_case_sensitive = search_case_sensitive;
404 final void setShowBranchLengthValues( final boolean show_branch_length_values ) {
405 _show_branch_length_values = show_branch_length_values;
408 public void setShowDomainLabels( final boolean show_domain_labels ) {
409 _show_domain_labels = show_domain_labels;
412 final void setShowOverview( final boolean show_overview ) {
413 _show_overview = show_overview;
416 final void setShowScale( final boolean show_scale ) {
417 _show_scale = show_scale;
420 void setTaxonomyColorizeNodeShapes( final boolean taxonomy_colorize_node_shapes ) {
421 _taxonomy_colorize_node_shapes = taxonomy_colorize_node_shapes;
424 final static Options createDefaultInstance() {
425 return new Options();
428 boolean isShowDefaultNodeShapes() {
429 return _show_default_node_shapes;
432 void setShowDefaultNodeShapes( final boolean show_default_node_shapes ) {
433 _show_default_node_shapes = show_default_node_shapes;
436 final static Options createInstance( final Configuration configuration ) {
437 final Options instance = createDefaultInstance();
438 if ( configuration != null ) {
439 instance.setAntialiasScreen( configuration.isAntialiasScreen() );
440 instance.setShowScale( configuration.isShowScale() );
441 instance.setShowBranchLengthValues( configuration.isShowBranchLengthValues() );
442 instance.setShowOverview( configuration.isShowOverview() );
443 instance.setCladogramType( configuration.getCladogramType() );
444 instance.setOvPlacement( configuration.getOvPlacement() );
445 instance.setPrintLineWidth( configuration.getPrintLineWidth() );
446 instance.setNodeLabelDirection( configuration.getNodeLabelDirection() );
447 instance.setBackgroundColorGradient( configuration.isBackgroundColorGradient() );
448 if ( configuration.getNumberOfDigitsAfterCommaForBranchLengthValues() >= 0 ) {
449 instance.setNumberOfDigitsAfterCommaForBranchLength( configuration
450 .getNumberOfDigitsAfterCommaForBranchLengthValues() );
452 if ( configuration.getNumberOfDigitsAfterCommaForConfidenceValues() >= 0 ) {
453 instance.setNumberOfDigitsAfterCommaForConfidenceValues( configuration
454 .getNumberOfDigitsAfterCommaForConfidenceValues() );
456 instance.setExtractPfamTaxonomyCodesInNhParsing( configuration.isExtractPfamTaxonomyCodesInNhParsing() );
457 instance.setReplaceUnderscoresInNhParsing( configuration.isReplaceUnderscoresInNhParsing() );
458 instance.setInternalNumberAreConfidenceForNhParsing( configuration
459 .isInternalNumberAreConfidenceForNhParsing() );
460 instance.setEditable( configuration.isEditable() );
461 instance.setColorLabelsSameAsParentBranch( configuration.isColorLabelsSameAsParentBranch() );
462 instance.setShowDomainLabels( configuration.isShowDomainLabels() );
463 instance.setAbbreviateScientificTaxonNames( configuration.isAbbreviateScientificTaxonNames() );
464 if ( configuration.getMinConfidenceValue() != MIN_CONFIDENCE_DEFAULT ) {
465 instance.setMinConfidenceValue( configuration.getMinConfidenceValue() );
467 if ( configuration.getGraphicsExportX() > 0 ) {
468 instance.setPrintSizeX( configuration.getGraphicsExportX() );
470 if ( configuration.getGraphicsExportY() > 0 ) {
471 instance.setPrintSizeY( configuration.getGraphicsExportY() );
473 if ( configuration.getBaseFontSize() > 0 ) {
474 instance.setBaseFont( instance.getBaseFont().deriveFont( ( float ) configuration.getBaseFontSize() ) );
476 if ( !ForesterUtil.isEmpty( configuration.getBaseFontFamilyName() ) ) {
477 instance.setBaseFont( new Font( configuration.getBaseFontFamilyName(), Font.PLAIN, instance
478 .getBaseFont().getSize() ) );
480 if ( configuration.getPhylogenyGraphicsType() != null ) {
481 instance.setPhylogenyGraphicsType( configuration.getPhylogenyGraphicsType() );
483 if ( configuration.getDefaultNodeFill() != null ) {
484 instance.setDefaultNodeFill( configuration.getDefaultNodeFill() );
486 if ( configuration.getDefaultNodeShape() != null ) {
487 instance.setDefaultNodeShape( configuration.getDefaultNodeShape() );
489 if ( configuration.getDefaultNodeShapeSize() >= 0 ) {
490 instance.setDefaultNodeShapeSize( configuration.getDefaultNodeShapeSize() );
492 instance.setTaxonomyColorizeNodeShapes( configuration.isTaxonomyColorizeNodeShapes() );
493 instance.setShowDefaultNodeShapes( configuration.isShowDefaultNodeShapes() );
498 static enum CLADOGRAM_TYPE {
499 NON_LINED_UP, EXT_NODE_SUM_DEP, TOTAL_NODE_SUM_DEP;
502 static enum NODE_LABEL_DIRECTION {
507 NONE, GRADIENT, SOLID
514 static enum OVERVIEW_PLACEMENT_TYPE {
515 UPPER_LEFT( "upper left" ),
516 UPPER_RIGHT( "upper right" ),
517 LOWER_LEFT( "lower left" ),
518 LOWER_RIGHT( "lower right" );
520 private final String _name;
522 private OVERVIEW_PLACEMENT_TYPE( final String name ) {
527 public String toString() {
531 public String toTag() {
532 return toString().replaceAll( " ", "_" );
536 static enum PHYLOGENY_GRAPHICS_TYPE {
537 RECTANGULAR, TRIANGULAR, EURO_STYLE, ROUNDED, CONVEX, CURVED, UNROOTED, CIRCULAR;