in progress
[jalview.git] / forester / java / src / org / forester / archaeopteryx / Options.java
1 // $Id:
2 // FORESTER -- software libraries and applications
3 // for evolutionary biology research and applications.
4 //
5 // Copyright (C) 2009 Christian M. Zmasek
6 // Copyright (C) 2009 Burnham Institute for Medical Research
7 // All rights reserved
8 //
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.
13 //
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.
18 //
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
22 //
23 // Contact: phylosoft @ gmail . com
24 // WWW: www.phylosoft.org/forester
25
26 package org.forester.archaeopteryx;
27
28 import java.awt.Font;
29
30 import org.forester.phylogeny.PhylogenyNodeI.NH_CONVERSION_SUPPORT_VALUE_STYLE;
31 import org.forester.phylogeny.data.NodeVisualization;
32 import org.forester.phylogeny.data.NodeVisualization.NodeFill;
33 import org.forester.phylogeny.data.NodeVisualization.NodeShape;
34 import org.forester.util.ForesterUtil;
35
36 /*
37  * This is to hold changeable options.
38  */
39 final public class Options {
40
41     static final double                       MIN_CONFIDENCE_DEFAULT = 0.0;
42     private boolean                           _show_branch_length_values;
43     private boolean                           _internal_number_are_confidence_for_nh_parsing;
44     private boolean                           _show_scale;
45     private boolean                           _show_overview;
46     private boolean                           _antialias_screen;
47     private boolean                           _antialias_print;
48     private boolean                           _graphics_export_visible_only;
49     private int                               _print_size_x;
50     private int                               _print_size_y;
51     private double                            _min_confidence_value;
52     private boolean                           _print_black_and_white;
53     private boolean                           _print_using_actual_size;
54     private boolean                           _graphics_export_using_actual_size;
55     private PHYLOGENY_GRAPHICS_TYPE           _phylogeny_graphics_type;
56     private CLADOGRAM_TYPE                    _cladogram_type;
57     private OVERVIEW_PLACEMENT_TYPE           _ov_placement;
58     private NODE_LABEL_DIRECTION              _node_label_direction;
59     private Font                              _base_font;
60     private boolean                           _match_whole_terms_only;
61     private boolean                           _search_case_sensitive;
62     private float                             _print_line_width;
63     private boolean                           _inverse_search_result;
64     private double                            _scale_bar_length;
65     private short                             _number_of_digits_after_comma_for_confidence_values;
66     private short                             _number_of_digits_after_comma_for_branch_length_values;
67     private boolean                           _nh_parsing_replace_underscores;
68     private boolean                           _nh_parsing_extract_pfam_taxonomy_codes;
69     private boolean                           _editable;
70     private boolean                           _background_color_gradient;
71     private boolean                           _show_domain_labels;
72     private boolean                           _color_labels_same_as_parent_branch;
73     private boolean                           _abbreviate_scientific_names;
74     private NodeVisualization.NodeShape       _default_node_shape;
75     private NodeVisualization.NodeFill        _default_node_fill;
76     private short                             _default_node_shape_size;
77     private boolean                           _taxonomy_colorize_node_shapes;
78     private boolean                           _show_default_node_shapes;
79     private boolean                           _show_confidence_stddev;
80     private NH_CONVERSION_SUPPORT_VALUE_STYLE _nh_conversion_support_value_style;
81
82     private Options() {
83         init();
84     }
85
86     final Font getBaseFont() {
87         return _base_font;
88     }
89
90     final CLADOGRAM_TYPE getCladogramType() {
91         return _cladogram_type;
92     }
93
94     final NodeFill getDefaultNodeFill() {
95         return _default_node_fill;
96     }
97
98     final NodeShape getDefaultNodeShape() {
99         return _default_node_shape;
100     }
101
102     final short getDefaultNodeShapeSize() {
103         return _default_node_shape_size;
104     }
105
106     final double getMinConfidenceValue() {
107         return _min_confidence_value;
108     }
109
110     final NODE_LABEL_DIRECTION getNodeLabelDirection() {
111         return _node_label_direction;
112     }
113
114     final short getNumberOfDigitsAfterCommaForBranchLengthValues() {
115         return _number_of_digits_after_comma_for_branch_length_values;
116     }
117
118     final short getNumberOfDigitsAfterCommaForConfidenceValues() {
119         return _number_of_digits_after_comma_for_confidence_values;
120     }
121
122     final OVERVIEW_PLACEMENT_TYPE getOvPlacement() {
123         return _ov_placement;
124     }
125
126     final PHYLOGENY_GRAPHICS_TYPE getPhylogenyGraphicsType() {
127         return _phylogeny_graphics_type;
128     }
129
130     final float getPrintLineWidth() {
131         return _print_line_width;
132     }
133
134     final int getPrintSizeX() {
135         return _print_size_x;
136     }
137
138     final int getPrintSizeY() {
139         return _print_size_y;
140     }
141
142     final double getScaleBarLength() {
143         return _scale_bar_length;
144     }
145
146     final private void init() {
147         _default_node_shape = NodeShape.CIRCLE;
148         _default_node_fill = NodeFill.GRADIENT;
149         _default_node_shape_size = Constants.DEFAULT_NODE_SHAPE_SIZE_DEFAULT;
150         _taxonomy_colorize_node_shapes = false;
151         _show_branch_length_values = false;
152         _internal_number_are_confidence_for_nh_parsing = false;
153         _show_scale = false;
154         _antialias_screen = true;
155         _antialias_print = true;
156         _graphics_export_visible_only = false;
157         _editable = true;
158         _background_color_gradient = false;
159         _show_default_node_shapes = false;
160         if ( AptxUtil.isUsOrCanada() ) {
161             _print_size_x = Constants.US_LETTER_SIZE_X;
162             _print_size_y = Constants.US_LETTER_SIZE_Y;
163         }
164         else {
165             _print_size_x = Constants.A4_SIZE_X;
166             _print_size_y = Constants.A4_SIZE_Y;
167         }
168         _min_confidence_value = MIN_CONFIDENCE_DEFAULT;
169         _print_black_and_white = false;
170         _print_using_actual_size = false;
171         _graphics_export_using_actual_size = true;
172         _phylogeny_graphics_type = PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR;
173         _base_font = new Font( Configuration.getDefaultFontFamilyName(), Font.PLAIN, 10 );
174         _match_whole_terms_only = false;
175         _search_case_sensitive = false;
176         _print_line_width = Constants.PDF_LINE_WIDTH_DEFAULT;
177         _show_overview = true;
178         _ov_placement = OVERVIEW_PLACEMENT_TYPE.UPPER_LEFT;
179         _node_label_direction = NODE_LABEL_DIRECTION.HORIZONTAL;
180         _inverse_search_result = false;
181         _scale_bar_length = 0.0;
182         _number_of_digits_after_comma_for_branch_length_values = Constants.NUMBER_OF_DIGITS_AFTER_COMMA_FOR_BRANCH_LENGTH_VALUES_DEFAULT;
183         _number_of_digits_after_comma_for_confidence_values = Constants.NUMBER_OF_DIGITS_AFTER_COMMA_FOR_CONFIDENCE_VALUES_DEFAULT;
184         _nh_parsing_replace_underscores = false;
185         _nh_parsing_extract_pfam_taxonomy_codes = false;
186         _cladogram_type = Constants.CLADOGRAM_TYPE_DEFAULT;
187         _show_domain_labels = true;
188         setAbbreviateScientificTaxonNames( false );
189         _color_labels_same_as_parent_branch = false;
190         _show_confidence_stddev = true;
191         _nh_conversion_support_value_style = NH_CONVERSION_SUPPORT_VALUE_STYLE.NONE;
192     }
193
194     boolean isShowConfidenceStddev() {
195         return _show_confidence_stddev;
196     }
197
198     void setShowConfidenceStddev( final boolean show_confidence_stddev ) {
199         _show_confidence_stddev = show_confidence_stddev;
200     }
201
202     NH_CONVERSION_SUPPORT_VALUE_STYLE getNhConversionSupportValueStyle() {
203         return _nh_conversion_support_value_style;
204     }
205
206     void setNhConversionSupportValueStyle( final NH_CONVERSION_SUPPORT_VALUE_STYLE nh_conversion_support_value_style ) {
207         _nh_conversion_support_value_style = nh_conversion_support_value_style;
208     }
209
210     final boolean isAbbreviateScientificTaxonNames() {
211         return _abbreviate_scientific_names;
212     }
213
214     boolean isAllowMagnificationOfTaxonomyImages() {
215         return true;
216     }
217
218     final boolean isAntialiasPrint() {
219         return _antialias_print;
220     }
221
222     final boolean isAntialiasScreen() {
223         return _antialias_screen;
224     }
225
226     final boolean isBackgroundColorGradient() {
227         return _background_color_gradient;
228     }
229
230     final boolean isColorLabelsSameAsParentBranch() {
231         return _color_labels_same_as_parent_branch;
232     }
233
234     final boolean isEditable() {
235         return _editable;
236     }
237
238     final boolean isExtractPfamTaxonomyCodesInNhParsing() {
239         return _nh_parsing_extract_pfam_taxonomy_codes;
240     }
241
242     final boolean isGraphicsExportUsingActualSize() {
243         return _graphics_export_using_actual_size;
244     }
245
246     final boolean isGraphicsExportVisibleOnly() {
247         return _graphics_export_visible_only;
248     }
249
250     final boolean isInternalNumberAreConfidenceForNhParsing() {
251         return _internal_number_are_confidence_for_nh_parsing;
252     }
253
254     final boolean isInverseSearchResult() {
255         return _inverse_search_result;
256     }
257
258     final boolean isMatchWholeTermsOnly() {
259         return _match_whole_terms_only;
260     }
261
262     final boolean isPrintBlackAndWhite() {
263         return _print_black_and_white;
264     }
265
266     final boolean isPrintUsingActualSize() {
267         return _print_using_actual_size;
268     }
269
270     final boolean isReplaceUnderscoresInNhParsing() {
271         return _nh_parsing_replace_underscores;
272     }
273
274     final boolean isSearchCaseSensitive() {
275         return _search_case_sensitive;
276     }
277
278     final boolean isShowBranchLengthValues() {
279         return _show_branch_length_values;
280     }
281
282     public final boolean isShowDomainLabels() {
283         return _show_domain_labels;
284     }
285
286     final boolean isShowOverview() {
287         return _show_overview;
288     }
289
290     final boolean isShowScale() {
291         return _show_scale;
292     }
293
294     boolean isTaxonomyColorizeNodeShapes() {
295         return _taxonomy_colorize_node_shapes;
296     }
297
298     final void setAbbreviateScientificTaxonNames( final boolean abbreviate_scientific_names ) {
299         _abbreviate_scientific_names = abbreviate_scientific_names;
300     }
301
302     final void setAntialiasPrint( final boolean antialias_print ) {
303         _antialias_print = antialias_print;
304     }
305
306     final void setAntialiasScreen( final boolean antialias_screen ) {
307         _antialias_screen = antialias_screen;
308     }
309
310     public void setBackgroundColorGradient( final boolean background_color_gradient ) {
311         _background_color_gradient = background_color_gradient;
312     }
313
314     final void setBaseFont( final Font base_font ) {
315         _base_font = base_font;
316     }
317
318     final void setCladogramType( final CLADOGRAM_TYPE cladogram_type ) {
319         _cladogram_type = cladogram_type;
320     }
321
322     public void setColorLabelsSameAsParentBranch( final boolean color_labels_same_as_parent_branch ) {
323         _color_labels_same_as_parent_branch = color_labels_same_as_parent_branch;
324     }
325
326     final void setDefaultNodeFill( final NodeFill default_node_fill ) {
327         _default_node_fill = default_node_fill;
328     }
329
330     final void setDefaultNodeShape( final NodeShape default_node_shape ) {
331         _default_node_shape = default_node_shape;
332     }
333
334     final void setDefaultNodeShapeSize( final short default_node_shape_size ) {
335         _default_node_shape_size = default_node_shape_size;
336     }
337
338     final void setEditable( final boolean editable ) {
339         _editable = editable;
340     }
341
342     final void setExtractPfamTaxonomyCodesInNhParsing( final boolean nh_parsing_extract_pfam_taxonomy_codes ) {
343         _nh_parsing_extract_pfam_taxonomy_codes = nh_parsing_extract_pfam_taxonomy_codes;
344     }
345
346     final void setGraphicsExportUsingActualSize( final boolean graphics_export_using_actual_size ) {
347         _graphics_export_using_actual_size = graphics_export_using_actual_size;
348         if ( !graphics_export_using_actual_size ) {
349             setGraphicsExportVisibleOnly( false );
350         }
351     }
352
353     final void setGraphicsExportVisibleOnly( final boolean graphics_export_visible_only ) {
354         _graphics_export_visible_only = graphics_export_visible_only;
355         if ( graphics_export_visible_only ) {
356             setGraphicsExportUsingActualSize( true );
357         }
358     }
359
360     final void setInternalNumberAreConfidenceForNhParsing( final boolean internal_number_are_confidence_for_nh_parsing ) {
361         _internal_number_are_confidence_for_nh_parsing = internal_number_are_confidence_for_nh_parsing;
362     }
363
364     final void setInverseSearchResult( final boolean inverse_search_result ) {
365         _inverse_search_result = inverse_search_result;
366     }
367
368     final void setMatchWholeTermsOnly( final boolean search_whole_words_only ) {
369         _match_whole_terms_only = search_whole_words_only;
370     }
371
372     final void setMinConfidenceValue( final double min_confidence_value ) {
373         _min_confidence_value = min_confidence_value;
374     }
375
376     final void setNodeLabelDirection( final NODE_LABEL_DIRECTION node_label_direction ) {
377         _node_label_direction = node_label_direction;
378     }
379
380     final private void setNumberOfDigitsAfterCommaForBranchLength( final short number_of_digits_after_comma_for_branch_length_values ) {
381         _number_of_digits_after_comma_for_branch_length_values = number_of_digits_after_comma_for_branch_length_values;
382     }
383
384     final private void setNumberOfDigitsAfterCommaForConfidenceValues( final short number_of_digits_after_comma_for_confidence_values ) {
385         _number_of_digits_after_comma_for_confidence_values = number_of_digits_after_comma_for_confidence_values;
386     }
387
388     final void setOvPlacement( final OVERVIEW_PLACEMENT_TYPE ov_placement ) {
389         _ov_placement = ov_placement;
390     }
391
392     final void setPhylogenyGraphicsType( final PHYLOGENY_GRAPHICS_TYPE phylogeny_graphics_type ) {
393         _phylogeny_graphics_type = phylogeny_graphics_type;
394     }
395
396     final void setPrintBlackAndWhite( final boolean print_black_and_white ) {
397         _print_black_and_white = print_black_and_white;
398     }
399
400     final void setPrintLineWidth( final float print_line_width ) {
401         _print_line_width = print_line_width;
402     }
403
404     final void setPrintSizeX( final int print_size_x ) {
405         _print_size_x = print_size_x;
406     }
407
408     final void setPrintSizeY( final int print_size_y ) {
409         _print_size_y = print_size_y;
410     }
411
412     final void setPrintUsingActualSize( final boolean print_using_actual_size ) {
413         _print_using_actual_size = print_using_actual_size;
414     }
415
416     final void setReplaceUnderscoresInNhParsing( final boolean nh_parsing_replace_underscores ) {
417         _nh_parsing_replace_underscores = nh_parsing_replace_underscores;
418     }
419
420     final void setScaleBarLength( final double scale_bar_length ) {
421         _scale_bar_length = scale_bar_length;
422     }
423
424     final void setSearchCaseSensitive( final boolean search_case_sensitive ) {
425         _search_case_sensitive = search_case_sensitive;
426     }
427
428     final void setShowBranchLengthValues( final boolean show_branch_length_values ) {
429         _show_branch_length_values = show_branch_length_values;
430     }
431
432     public void setShowDomainLabels( final boolean show_domain_labels ) {
433         _show_domain_labels = show_domain_labels;
434     }
435
436     final void setShowOverview( final boolean show_overview ) {
437         _show_overview = show_overview;
438     }
439
440     final void setShowScale( final boolean show_scale ) {
441         _show_scale = show_scale;
442     }
443
444     void setTaxonomyColorizeNodeShapes( final boolean taxonomy_colorize_node_shapes ) {
445         _taxonomy_colorize_node_shapes = taxonomy_colorize_node_shapes;
446     }
447
448     final static Options createDefaultInstance() {
449         return new Options();
450     }
451
452     boolean isShowDefaultNodeShapes() {
453         return _show_default_node_shapes;
454     }
455
456     void setShowDefaultNodeShapes( final boolean show_default_node_shapes ) {
457         _show_default_node_shapes = show_default_node_shapes;
458     }
459
460     public final static Options createInstance( final Configuration configuration ) {
461         final Options instance = createDefaultInstance();
462         if ( configuration != null ) {
463             instance.setAntialiasScreen( configuration.isAntialiasScreen() );
464             instance.setShowScale( configuration.isShowScale() );
465             instance.setShowBranchLengthValues( configuration.isShowBranchLengthValues() );
466             instance.setShowOverview( configuration.isShowOverview() );
467             instance.setCladogramType( configuration.getCladogramType() );
468             instance.setOvPlacement( configuration.getOvPlacement() );
469             instance.setPrintLineWidth( configuration.getPrintLineWidth() );
470             instance.setNodeLabelDirection( configuration.getNodeLabelDirection() );
471             instance.setBackgroundColorGradient( configuration.isBackgroundColorGradient() );
472             if ( configuration.getNumberOfDigitsAfterCommaForBranchLengthValues() >= 0 ) {
473                 instance.setNumberOfDigitsAfterCommaForBranchLength( configuration
474                         .getNumberOfDigitsAfterCommaForBranchLengthValues() );
475             }
476             if ( configuration.getNumberOfDigitsAfterCommaForConfidenceValues() >= 0 ) {
477                 instance.setNumberOfDigitsAfterCommaForConfidenceValues( configuration
478                         .getNumberOfDigitsAfterCommaForConfidenceValues() );
479             }
480             instance.setExtractPfamTaxonomyCodesInNhParsing( configuration.isExtractPfamTaxonomyCodesInNhParsing() );
481             instance.setReplaceUnderscoresInNhParsing( configuration.isReplaceUnderscoresInNhParsing() );
482             instance.setInternalNumberAreConfidenceForNhParsing( configuration
483                     .isInternalNumberAreConfidenceForNhParsing() );
484             instance.setEditable( configuration.isEditable() );
485             instance.setColorLabelsSameAsParentBranch( configuration.isColorLabelsSameAsParentBranch() );
486             instance.setShowDomainLabels( configuration.isShowDomainLabels() );
487             instance.setAbbreviateScientificTaxonNames( configuration.isAbbreviateScientificTaxonNames() );
488             if ( configuration.getMinConfidenceValue() != MIN_CONFIDENCE_DEFAULT ) {
489                 instance.setMinConfidenceValue( configuration.getMinConfidenceValue() );
490             }
491             if ( configuration.getGraphicsExportX() > 0 ) {
492                 instance.setPrintSizeX( configuration.getGraphicsExportX() );
493             }
494             if ( configuration.getGraphicsExportY() > 0 ) {
495                 instance.setPrintSizeY( configuration.getGraphicsExportY() );
496             }
497             if ( configuration.getBaseFontSize() > 0 ) {
498                 instance.setBaseFont( instance.getBaseFont().deriveFont( ( float ) configuration.getBaseFontSize() ) );
499             }
500             if ( !ForesterUtil.isEmpty( configuration.getBaseFontFamilyName() ) ) {
501                 instance.setBaseFont( new Font( configuration.getBaseFontFamilyName(), Font.PLAIN, instance
502                         .getBaseFont().getSize() ) );
503             }
504             if ( configuration.getPhylogenyGraphicsType() != null ) {
505                 instance.setPhylogenyGraphicsType( configuration.getPhylogenyGraphicsType() );
506             }
507             if ( configuration.getDefaultNodeFill() != null ) {
508                 instance.setDefaultNodeFill( configuration.getDefaultNodeFill() );
509             }
510             if ( configuration.getDefaultNodeShape() != null ) {
511                 instance.setDefaultNodeShape( configuration.getDefaultNodeShape() );
512             }
513             if ( configuration.getDefaultNodeShapeSize() >= 0 ) {
514                 instance.setDefaultNodeShapeSize( configuration.getDefaultNodeShapeSize() );
515             }
516             instance.setTaxonomyColorizeNodeShapes( configuration.isTaxonomyColorizeNodeShapes() );
517             instance.setShowDefaultNodeShapes( configuration.isShowDefaultNodeShapes() );
518         }
519         return instance;
520     }
521
522     public static enum CLADOGRAM_TYPE {
523         NON_LINED_UP, EXT_NODE_SUM_DEP, TOTAL_NODE_SUM_DEP;
524     }
525
526     public static enum NODE_LABEL_DIRECTION {
527         HORIZONTAL, RADIAL;
528     }
529
530     static enum OVERVIEW_PLACEMENT_TYPE {
531         UPPER_LEFT( "upper left" ),
532         UPPER_RIGHT( "upper right" ),
533         LOWER_LEFT( "lower left" ),
534         LOWER_RIGHT( "lower right" );
535
536         private final String _name;
537
538         private OVERVIEW_PLACEMENT_TYPE( final String name ) {
539             _name = name;
540         }
541
542         @Override
543         public String toString() {
544             return _name;
545         }
546
547         public String toTag() {
548             return toString().replaceAll( " ", "_" );
549         }
550     }
551
552     public static enum PHYLOGENY_GRAPHICS_TYPE {
553         RECTANGULAR, TRIANGULAR, EURO_STYLE, ROUNDED, CONVEX, CURVED, UNROOTED, CIRCULAR;
554     }
555 }