31c987367f33b5e05b6bc3292c04d201b88dd257
[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.util.ForesterUtil;
31
32 /*
33  * This is to hold changeable options.
34  */
35 final public class Options {
36
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;
74
75     private Options() {
76         init();
77     }
78
79     final Font getBaseFont() {
80         return _base_font;
81     }
82
83     final CLADOGRAM_TYPE getCladogramType() {
84         return _cladogram_type;
85     }
86
87     int getDefaultNodeBoxSize() {
88         // TODO make variable ~~
89         return 8;
90     }
91
92     final NodeFill getDefaultNodeFill() {
93         return _default_node_fill;
94     }
95
96     final NodeShape getDefaultNodeShape() {
97         return _default_node_shape;
98     }
99
100     final short getDefaultNodeShapeSize() {
101         return _default_node_shape_size;
102     }
103
104     final double getMinConfidenceValue() {
105         return _min_confidence_value;
106     }
107
108     final NODE_LABEL_DIRECTION getNodeLabelDirection() {
109         return _node_label_direction;
110     }
111
112     final short getNumberOfDigitsAfterCommaForBranchLengthValues() {
113         return _number_of_digits_after_comma_for_branch_length_values;
114     }
115
116     final short getNumberOfDigitsAfterCommaForConfidenceValues() {
117         return _number_of_digits_after_comma_for_confidence_values;
118     }
119
120     final OVERVIEW_PLACEMENT_TYPE getOvPlacement() {
121         return _ov_placement;
122     }
123
124     final PHYLOGENY_GRAPHICS_TYPE getPhylogenyGraphicsType() {
125         return _phylogeny_graphics_type;
126     }
127
128     final float getPrintLineWidth() {
129         return _print_line_width;
130     }
131
132     final int getPrintSizeX() {
133         return _print_size_x;
134     }
135
136     final int getPrintSizeY() {
137         return _print_size_y;
138     }
139
140     final double getScaleBarLength() {
141         return _scale_bar_length;
142     }
143
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;
151         _show_scale = false;
152         _antialias_screen = true;
153         _antialias_print = true;
154         _graphics_export_visible_only = false;
155         _editable = true;
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;
160         }
161         else {
162             _print_size_x = Constants.A4_SIZE_X;
163             _print_size_y = Constants.A4_SIZE_Y;
164         }
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;
187     }
188
189     final boolean isAbbreviateScientificTaxonNames() {
190         return _abbreviate_scientific_names;
191     }
192
193     boolean isAllowMagnificationOfTaxonomyImages() {
194         return true;
195     }
196
197     final boolean isAntialiasPrint() {
198         return _antialias_print;
199     }
200
201     final boolean isAntialiasScreen() {
202         return _antialias_screen;
203     }
204
205     final boolean isBackgroundColorGradient() {
206         return _background_color_gradient;
207     }
208
209     final boolean isColorLabelsSameAsParentBranch() {
210         return _color_labels_same_as_parent_branch;
211     }
212
213     final boolean isEditable() {
214         return _editable;
215     }
216
217     final boolean isExtractPfamTaxonomyCodesInNhParsing() {
218         return _nh_parsing_extract_pfam_taxonomy_codes;
219     }
220
221     final boolean isGraphicsExportUsingActualSize() {
222         return _graphics_export_using_actual_size;
223     }
224
225     final boolean isGraphicsExportVisibleOnly() {
226         return _graphics_export_visible_only;
227     }
228
229     final boolean isInternalNumberAreConfidenceForNhParsing() {
230         return _internal_number_are_confidence_for_nh_parsing;
231     }
232
233     final boolean isInverseSearchResult() {
234         return _inverse_search_result;
235     }
236
237     final boolean isMatchWholeTermsOnly() {
238         return _match_whole_terms_only;
239     }
240
241     final boolean isPrintBlackAndWhite() {
242         return _print_black_and_white;
243     }
244
245     final boolean isPrintUsingActualSize() {
246         return _print_using_actual_size;
247     }
248
249     final boolean isReplaceUnderscoresInNhParsing() {
250         return _nh_parsing_replace_underscores;
251     }
252
253     final boolean isSearchCaseSensitive() {
254         return _search_case_sensitive;
255     }
256
257     final boolean isShowBranchLengthValues() {
258         return _show_branch_length_values;
259     }
260
261     public final boolean isShowDomainLabels() {
262         return _show_domain_labels;
263     }
264
265     final boolean isShowOverview() {
266         return _show_overview;
267     }
268
269     final boolean isShowScale() {
270         return _show_scale;
271     }
272
273     boolean isTaxonomyColorizeNodeShapesInsteadOfLabels() {
274         return _taxonomy_colorize_node_shapes_instead_of_labels;
275     }
276
277     final void setAbbreviateScientificTaxonNames( final boolean abbreviate_scientific_names ) {
278         _abbreviate_scientific_names = abbreviate_scientific_names;
279     }
280
281     final void setAntialiasPrint( final boolean antialias_print ) {
282         _antialias_print = antialias_print;
283     }
284
285     final void setAntialiasScreen( final boolean antialias_screen ) {
286         _antialias_screen = antialias_screen;
287     }
288
289     public void setBackgroundColorGradient( final boolean background_color_gradient ) {
290         _background_color_gradient = background_color_gradient;
291     }
292
293     final void setBaseFont( final Font base_font ) {
294         _base_font = base_font;
295     }
296
297     final void setCladogramType( final CLADOGRAM_TYPE cladogram_type ) {
298         _cladogram_type = cladogram_type;
299     }
300
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;
303     }
304
305     final void setDefaultNodeFill( final NodeFill default_node_fill ) {
306         _default_node_fill = default_node_fill;
307     }
308
309     final void setDefaultNodeShape( final NodeShape default_node_shape ) {
310         _default_node_shape = default_node_shape;
311     }
312
313     final void setDefaultNodeShapeSize( final short default_node_shape_size ) {
314         _default_node_shape_size = default_node_shape_size;
315     }
316
317     final void setEditable( final boolean editable ) {
318         _editable = editable;
319     }
320
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;
323     }
324
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 );
329         }
330     }
331
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 );
336         }
337     }
338
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;
341     }
342
343     final void setInverseSearchResult( final boolean inverse_search_result ) {
344         _inverse_search_result = inverse_search_result;
345     }
346
347     final void setMatchWholeTermsOnly( final boolean search_whole_words_only ) {
348         _match_whole_terms_only = search_whole_words_only;
349     }
350
351     final void setMinConfidenceValue( final double min_confidence_value ) {
352         _min_confidence_value = min_confidence_value;
353     }
354
355     final void setNodeLabelDirection( final NODE_LABEL_DIRECTION node_label_direction ) {
356         _node_label_direction = node_label_direction;
357     }
358
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;
361     }
362
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;
365     }
366
367     final void setOvPlacement( final OVERVIEW_PLACEMENT_TYPE ov_placement ) {
368         _ov_placement = ov_placement;
369     }
370
371     final void setPhylogenyGraphicsType( final PHYLOGENY_GRAPHICS_TYPE phylogeny_graphics_type ) {
372         _phylogeny_graphics_type = phylogeny_graphics_type;
373     }
374
375     final void setPrintBlackAndWhite( final boolean print_black_and_white ) {
376         _print_black_and_white = print_black_and_white;
377     }
378
379     final void setPrintLineWidth( final float print_line_width ) {
380         _print_line_width = print_line_width;
381     }
382
383     final void setPrintSizeX( final int print_size_x ) {
384         _print_size_x = print_size_x;
385     }
386
387     final void setPrintSizeY( final int print_size_y ) {
388         _print_size_y = print_size_y;
389     }
390
391     final void setPrintUsingActualSize( final boolean print_using_actual_size ) {
392         _print_using_actual_size = print_using_actual_size;
393     }
394
395     final void setReplaceUnderscoresInNhParsing( final boolean nh_parsing_replace_underscores ) {
396         _nh_parsing_replace_underscores = nh_parsing_replace_underscores;
397     }
398
399     final void setScaleBarLength( final double scale_bar_length ) {
400         _scale_bar_length = scale_bar_length;
401     }
402
403     final void setSearchCaseSensitive( final boolean search_case_sensitive ) {
404         _search_case_sensitive = search_case_sensitive;
405     }
406
407     final void setShowBranchLengthValues( final boolean show_branch_length_values ) {
408         _show_branch_length_values = show_branch_length_values;
409     }
410
411     public void setShowDomainLabels( final boolean show_domain_labels ) {
412         _show_domain_labels = show_domain_labels;
413     }
414
415     final void setShowOverview( final boolean show_overview ) {
416         _show_overview = show_overview;
417     }
418
419     final void setShowScale( final boolean show_scale ) {
420         _show_scale = show_scale;
421     }
422
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;
425     }
426
427     final static Options createDefaultInstance() {
428         return new Options();
429     }
430
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() );
446             }
447             if ( configuration.getNumberOfDigitsAfterCommaForConfidenceValues() >= 0 ) {
448                 instance.setNumberOfDigitsAfterCommaForConfidenceValues( configuration
449                         .getNumberOfDigitsAfterCommaForConfidenceValues() );
450             }
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() );
461             }
462             if ( configuration.getGraphicsExportX() > 0 ) {
463                 instance.setPrintSizeX( configuration.getGraphicsExportX() );
464             }
465             if ( configuration.getGraphicsExportY() > 0 ) {
466                 instance.setPrintSizeY( configuration.getGraphicsExportY() );
467             }
468             if ( configuration.getBaseFontSize() > 0 ) {
469                 instance.setBaseFont( instance.getBaseFont().deriveFont( ( float ) configuration.getBaseFontSize() ) );
470             }
471             if ( !ForesterUtil.isEmpty( configuration.getBaseFontFamilyName() ) ) {
472                 instance.setBaseFont( new Font( configuration.getBaseFontFamilyName(), Font.PLAIN, instance
473                         .getBaseFont().getSize() ) );
474             }
475             if ( configuration.getPhylogenyGraphicsType() != null ) {
476                 instance.setPhylogenyGraphicsType( configuration.getPhylogenyGraphicsType() );
477             }
478             if ( configuration.getDefaultNodeFill() != null ) {
479                 instance.setDefaultNodeFill( configuration.getDefaultNodeFill() );
480             }
481             if ( configuration.getDefaultNodeShape() != null ) {
482                 instance.setDefaultNodeShape( configuration.getDefaultNodeShape() );
483             }
484             if ( configuration.getDefaultNodeShapeSize() >= 0 ) {
485                 instance.setDefaultNodeShapeSize( configuration.getDefaultNodeShapeSize() );
486             }
487             instance.setTaxonomyColorizeNodeShapesInsteadOfLabels( configuration
488                     .isTaxonomyColorizeNodeShapesInsteadOfLabels() );
489         }
490         return instance;
491     }
492
493     static enum CLADOGRAM_TYPE {
494         NON_LINED_UP, EXT_NODE_SUM_DEP, TOTAL_NODE_SUM_DEP;
495     }
496
497     static enum NODE_LABEL_DIRECTION {
498         HORIZONTAL, RADIAL;
499     }
500
501     enum NodeFill {
502         NONE, GRADIENT, SOLID
503     }
504
505     enum NodeShape {
506         NONE, CIRCLE, RECTANGLE
507     }
508
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" );
514
515         private final String _name;
516
517         private OVERVIEW_PLACEMENT_TYPE( final String name ) {
518             _name = name;
519         }
520
521         @Override
522         public String toString() {
523             return _name;
524         }
525
526         public String toTag() {
527             return toString().replaceAll( " ", "_" );
528         }
529     }
530
531     static enum PHYLOGENY_GRAPHICS_TYPE {
532         RECTANGULAR, TRIANGULAR, EURO_STYLE, ROUNDED, CONVEX, CURVED, UNROOTED, CIRCULAR;
533     }
534 }