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 NodeShape _default_node_shape;
39 private boolean _show_branch_length_values;
40 private boolean _internal_number_are_confidence_for_nh_parsing;
41 private boolean _show_scale;
42 private boolean _show_overview;
43 private boolean _antialias_screen;
44 private boolean _antialias_print;
45 private boolean _graphics_export_visible_only;
46 private int _print_size_x;
47 private int _print_size_y;
48 private double _min_confidence_value;
49 private boolean _print_black_and_white;
50 private boolean _print_using_actual_size;
51 private boolean _graphics_export_using_actual_size;
52 private PHYLOGENY_GRAPHICS_TYPE _phylogeny_graphics_type;
53 private CLADOGRAM_TYPE _cladogram_type;
54 private OVERVIEW_PLACEMENT_TYPE _ov_placement;
55 private NODE_LABEL_DIRECTION _node_label_direction;
56 private Font _base_font;
57 private boolean _match_whole_terms_only;
58 private boolean _search_case_sensitive;
59 private float _print_line_width;
60 private boolean _inverse_search_result;
61 private double _scale_bar_length;
62 private short _number_of_digits_after_comma_for_confidence_values;
63 private short _number_of_digits_after_comma_for_branch_length_values;
64 private boolean _nh_parsing_replace_underscores;
65 private boolean _nh_parsing_extract_pfam_taxonomy_codes;
66 private boolean _editable;
67 private boolean _background_color_gradient;
68 private boolean _show_domain_labels;
69 private boolean _color_labels_same_as_parent_branch;
70 private boolean _abbreviate_scientific_names;
73 NONE, CIRCLE_WITH_GRADIENT, CIRCLE_SOLID, RECTANGLE_WITH_GRADIENT, RECTANGLE_SOLID;
80 final Font getBaseFont() {
84 final CLADOGRAM_TYPE getCladogramType() {
85 return _cladogram_type;
88 final double getMinConfidenceValue() {
89 return _min_confidence_value;
92 final NODE_LABEL_DIRECTION getNodeLabelDirection() {
93 return _node_label_direction;
96 final short getNumberOfDigitsAfterCommaForBranchLengthValues() {
97 return _number_of_digits_after_comma_for_branch_length_values;
100 final short getNumberOfDigitsAfterCommaForConfidenceValues() {
101 return _number_of_digits_after_comma_for_confidence_values;
104 final OVERVIEW_PLACEMENT_TYPE getOvPlacement() {
105 return _ov_placement;
108 final PHYLOGENY_GRAPHICS_TYPE getPhylogenyGraphicsType() {
109 return _phylogeny_graphics_type;
112 final float getPrintLineWidth() {
113 return _print_line_width;
116 final int getPrintSizeX() {
117 return _print_size_x;
120 final int getPrintSizeY() {
121 return _print_size_y;
124 final double getScaleBarLength() {
125 return _scale_bar_length;
128 final private void init() {
129 _default_node_shape = NodeShape.RECTANGLE_WITH_GRADIENT;
130 _show_branch_length_values = false;
131 _internal_number_are_confidence_for_nh_parsing = false;
133 _antialias_screen = true;
134 _antialias_print = true;
135 _graphics_export_visible_only = false;
137 _background_color_gradient = false;
138 if ( Util.isUsOrCanada() ) {
139 _print_size_x = Constants.US_LETTER_SIZE_X;
140 _print_size_y = Constants.US_LETTER_SIZE_Y;
143 _print_size_x = Constants.A4_SIZE_X;
144 _print_size_y = Constants.A4_SIZE_Y;
146 _min_confidence_value = MIN_CONFIDENCE_DEFAULT;
147 _print_black_and_white = false;
148 _print_using_actual_size = false;
149 _graphics_export_using_actual_size = true;
150 _phylogeny_graphics_type = PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR;
151 _base_font = new Font( Configuration.getDefaultFontFamilyName(), Font.PLAIN, 10 );
152 _match_whole_terms_only = false;
153 _search_case_sensitive = false;
154 _print_line_width = Constants.PDF_LINE_WIDTH_DEFAULT;
155 _show_overview = true;
156 _ov_placement = OVERVIEW_PLACEMENT_TYPE.UPPER_LEFT;
157 _node_label_direction = NODE_LABEL_DIRECTION.HORIZONTAL;
158 _inverse_search_result = false;
159 _scale_bar_length = 0.0;
160 _number_of_digits_after_comma_for_branch_length_values = Constants.NUMBER_OF_DIGITS_AFTER_COMMA_FOR_BRANCH_LENGTH_VALUES_DEFAULT;
161 _number_of_digits_after_comma_for_confidence_values = Constants.NUMBER_OF_DIGITS_AFTER_COMMA_FOR_CONFIDENCE_VALUES_DEFAULT;
162 _nh_parsing_replace_underscores = false;
163 _nh_parsing_extract_pfam_taxonomy_codes = false;
164 _cladogram_type = Constants.CLADOGRAM_TYPE_DEFAULT;
165 _show_domain_labels = true;
166 setAbbreviateScientificTaxonNames( false );
167 _color_labels_same_as_parent_branch = false;
170 final boolean isAntialiasPrint() {
171 return _antialias_print;
174 final boolean isAntialiasScreen() {
175 return _antialias_screen;
178 final boolean isBackgroundColorGradient() {
179 return _background_color_gradient;
182 public final boolean isShowDomainLabels() {
183 return _show_domain_labels;
186 final boolean isColorLabelsSameAsParentBranch() {
187 return _color_labels_same_as_parent_branch;
190 final boolean isEditable() {
194 final boolean isExtractPfamTaxonomyCodesInNhParsing() {
195 return _nh_parsing_extract_pfam_taxonomy_codes;
198 final boolean isGraphicsExportUsingActualSize() {
199 return _graphics_export_using_actual_size;
202 final boolean isGraphicsExportVisibleOnly() {
203 return _graphics_export_visible_only;
206 final boolean isInternalNumberAreConfidenceForNhParsing() {
207 return _internal_number_are_confidence_for_nh_parsing;
210 final boolean isInverseSearchResult() {
211 return _inverse_search_result;
214 final boolean isMatchWholeTermsOnly() {
215 return _match_whole_terms_only;
218 final boolean isPrintBlackAndWhite() {
219 return _print_black_and_white;
222 final boolean isPrintUsingActualSize() {
223 return _print_using_actual_size;
226 final boolean isReplaceUnderscoresInNhParsing() {
227 return _nh_parsing_replace_underscores;
230 final boolean isSearchCaseSensitive() {
231 return _search_case_sensitive;
234 final boolean isShowBranchLengthValues() {
235 return _show_branch_length_values;
238 final NodeShape getDefaultNodeShape() {
239 return _default_node_shape;
242 final boolean isShowOverview() {
243 return _show_overview;
246 final boolean isShowScale() {
250 final void setAntialiasPrint( final boolean antialias_print ) {
251 _antialias_print = antialias_print;
254 final void setAntialiasScreen( final boolean antialias_screen ) {
255 _antialias_screen = antialias_screen;
258 public void setBackgroundColorGradient( final boolean background_color_gradient ) {
259 _background_color_gradient = background_color_gradient;
262 public void setShowDomainLabels( final boolean show_domain_labels ) {
263 _show_domain_labels = show_domain_labels;
266 public void setColorLabelsSameAsParentBranch( final boolean color_labels_same_as_parent_branch ) {
267 _color_labels_same_as_parent_branch = color_labels_same_as_parent_branch;
270 final void setBaseFont( final Font base_font ) {
271 _base_font = base_font;
274 final void setCladogramType( final CLADOGRAM_TYPE cladogram_type ) {
275 _cladogram_type = cladogram_type;
278 final void setEditable( final boolean editable ) {
279 _editable = editable;
282 final void setExtractPfamTaxonomyCodesInNhParsing( final boolean nh_parsing_extract_pfam_taxonomy_codes ) {
283 _nh_parsing_extract_pfam_taxonomy_codes = nh_parsing_extract_pfam_taxonomy_codes;
286 final void setGraphicsExportUsingActualSize( final boolean graphics_export_using_actual_size ) {
287 _graphics_export_using_actual_size = graphics_export_using_actual_size;
288 if ( !graphics_export_using_actual_size ) {
289 setGraphicsExportVisibleOnly( false );
293 final void setGraphicsExportVisibleOnly( final boolean graphics_export_visible_only ) {
294 _graphics_export_visible_only = graphics_export_visible_only;
295 if ( graphics_export_visible_only ) {
296 setGraphicsExportUsingActualSize( true );
300 final void setInternalNumberAreConfidenceForNhParsing( final boolean internal_number_are_confidence_for_nh_parsing ) {
301 _internal_number_are_confidence_for_nh_parsing = internal_number_are_confidence_for_nh_parsing;
304 final void setInverseSearchResult( final boolean inverse_search_result ) {
305 _inverse_search_result = inverse_search_result;
308 final void setMatchWholeTermsOnly( final boolean search_whole_words_only ) {
309 _match_whole_terms_only = search_whole_words_only;
312 final void setMinConfidenceValue( final double min_confidence_value ) {
313 _min_confidence_value = min_confidence_value;
316 final void setNodeLabelDirection( final NODE_LABEL_DIRECTION node_label_direction ) {
317 _node_label_direction = node_label_direction;
320 final private void setNumberOfDigitsAfterCommaForBranchLength( final short number_of_digits_after_comma_for_branch_length_values ) {
321 _number_of_digits_after_comma_for_branch_length_values = number_of_digits_after_comma_for_branch_length_values;
324 final private void setNumberOfDigitsAfterCommaForConfidenceValues( final short number_of_digits_after_comma_for_confidence_values ) {
325 _number_of_digits_after_comma_for_confidence_values = number_of_digits_after_comma_for_confidence_values;
328 final void setOvPlacement( final OVERVIEW_PLACEMENT_TYPE ov_placement ) {
329 _ov_placement = ov_placement;
332 final void setPhylogenyGraphicsType( final PHYLOGENY_GRAPHICS_TYPE phylogeny_graphics_type ) {
333 _phylogeny_graphics_type = phylogeny_graphics_type;
336 final void setPrintBlackAndWhite( final boolean print_black_and_white ) {
337 _print_black_and_white = print_black_and_white;
340 final void setPrintLineWidth( final float print_line_width ) {
341 _print_line_width = print_line_width;
344 final void setPrintSizeX( final int print_size_x ) {
345 _print_size_x = print_size_x;
348 final void setPrintSizeY( final int print_size_y ) {
349 _print_size_y = print_size_y;
352 final void setPrintUsingActualSize( final boolean print_using_actual_size ) {
353 _print_using_actual_size = print_using_actual_size;
356 final void setReplaceUnderscoresInNhParsing( final boolean nh_parsing_replace_underscores ) {
357 _nh_parsing_replace_underscores = nh_parsing_replace_underscores;
360 final void setScaleBarLength( final double scale_bar_length ) {
361 _scale_bar_length = scale_bar_length;
364 final void setSearchCaseSensitive( final boolean search_case_sensitive ) {
365 _search_case_sensitive = search_case_sensitive;
368 final void setShowBranchLengthValues( final boolean show_branch_length_values ) {
369 _show_branch_length_values = show_branch_length_values;
372 final void setDefaultNodeShape( final NodeShape default_node_shape ) {
373 _default_node_shape = default_node_shape;
376 final void setShowOverview( final boolean show_overview ) {
377 _show_overview = show_overview;
380 final void setShowScale( final boolean show_scale ) {
381 _show_scale = show_scale;
384 final static Options createDefaultInstance() {
385 return new Options();
388 final static Options createInstance( final Configuration configuration ) {
389 final Options instance = createDefaultInstance();
390 if ( configuration != null ) {
391 instance.setAntialiasScreen( configuration.isAntialiasScreen() );
392 instance.setShowScale( configuration.isShowScale() );
393 instance.setShowBranchLengthValues( configuration.isShowBranchLengthValues() );
394 instance.setShowOverview( configuration.isShowOverview() );
395 instance.setCladogramType( configuration.getCladogramType() );
396 instance.setOvPlacement( configuration.getOvPlacement() );
397 instance.setPrintLineWidth( configuration.getPrintLineWidth() );
398 instance.setNodeLabelDirection( configuration.getNodeLabelDirection() );
399 instance.setBackgroundColorGradient( configuration.isBackgroundColorGradient() );
400 if ( configuration.getNumberOfDigitsAfterCommaForBranchLengthValues() >= 0 ) {
401 instance.setNumberOfDigitsAfterCommaForBranchLength( configuration
402 .getNumberOfDigitsAfterCommaForBranchLengthValues() );
404 if ( configuration.getNumberOfDigitsAfterCommaForConfidenceValues() >= 0 ) {
405 instance.setNumberOfDigitsAfterCommaForConfidenceValues( configuration
406 .getNumberOfDigitsAfterCommaForConfidenceValues() );
408 instance.setExtractPfamTaxonomyCodesInNhParsing( configuration.isExtractPfamTaxonomyCodesInNhParsing() );
409 instance.setReplaceUnderscoresInNhParsing( configuration.isReplaceUnderscoresInNhParsing() );
410 instance.setInternalNumberAreConfidenceForNhParsing( configuration
411 .isInternalNumberAreConfidenceForNhParsing() );
412 instance.setEditable( configuration.isEditable() );
413 instance.setColorLabelsSameAsParentBranch( configuration.isColorLabelsSameAsParentBranch() );
414 instance.setShowDomainLabels( configuration.isShowDomainLabels() );
415 instance.setAbbreviateScientificTaxonNames( configuration.isAbbreviateScientificTaxonNames() );
416 if ( configuration.getMinConfidenceValue() != MIN_CONFIDENCE_DEFAULT ) {
417 instance.setMinConfidenceValue( configuration.getMinConfidenceValue() );
419 if ( configuration.getGraphicsExportX() > 0 ) {
420 instance.setPrintSizeX( configuration.getGraphicsExportX() );
422 if ( configuration.getGraphicsExportY() > 0 ) {
423 instance.setPrintSizeY( configuration.getGraphicsExportY() );
425 if ( configuration.getBaseFontSize() > 0 ) {
426 instance.setBaseFont( instance.getBaseFont().deriveFont( ( float ) configuration.getBaseFontSize() ) );
428 if ( !ForesterUtil.isEmpty( configuration.getBaseFontFamilyName() ) ) {
429 instance.setBaseFont( new Font( configuration.getBaseFontFamilyName(), Font.PLAIN, instance
430 .getBaseFont().getSize() ) );
432 if ( configuration.getPhylogenyGraphicsType() != null ) {
433 instance.setPhylogenyGraphicsType( configuration.getPhylogenyGraphicsType() );
439 final void setAbbreviateScientificTaxonNames( final boolean abbreviate_scientific_names ) {
440 _abbreviate_scientific_names = abbreviate_scientific_names;
443 final boolean isAbbreviateScientificTaxonNames() {
444 return _abbreviate_scientific_names;
447 static enum CLADOGRAM_TYPE {
448 NON_LINED_UP, EXT_NODE_SUM_DEP, TOTAL_NODE_SUM_DEP;
451 static enum NODE_LABEL_DIRECTION {
455 static enum OVERVIEW_PLACEMENT_TYPE {
456 UPPER_LEFT( "upper left" ),
457 UPPER_RIGHT( "upper right" ),
458 LOWER_LEFT( "lower left" ),
459 LOWER_RIGHT( "lower right" );
461 private final String _name;
463 private OVERVIEW_PLACEMENT_TYPE( final String name ) {
468 public String toString() {
472 public String toTag() {
473 return toString().replaceAll( " ", "_" );
477 static enum PHYLOGENY_GRAPHICS_TYPE {
478 RECTANGULAR, TRIANGULAR, EURO_STYLE, ROUNDED, CONVEX, CURVED, UNROOTED, CIRCULAR;
481 boolean isAllowMagnificationOfTaxonomyImages() {
485 int getDefaultNodeBoxSize() {
486 // TODO make variable ~~