7f5cabddc8c8c694b46eee6374af3bc8e8a44a40
[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 short                   _default_node_shape_size;
72     private boolean                 _taxonomy_colorize_node_shapes_instead_of_labels;
73
74     enum NodeShape {
75         NONE,
76         CIRCLE_WITH_GRADIENT,
77         CIRCLE_SOLID,
78         CIRCLE_HOLLOW,
79         RECTANGLE_WITH_GRADIENT,
80         RECTANGLE_SOLID,
81         RECTANGLE_HOLLOW;
82     }
83
84     private Options() {
85         init();
86     }
87
88     final Font getBaseFont() {
89         return _base_font;
90     }
91
92     final CLADOGRAM_TYPE getCladogramType() {
93         return _cladogram_type;
94     }
95
96     final double getMinConfidenceValue() {
97         return _min_confidence_value;
98     }
99
100     final NODE_LABEL_DIRECTION getNodeLabelDirection() {
101         return _node_label_direction;
102     }
103
104     final short getNumberOfDigitsAfterCommaForBranchLengthValues() {
105         return _number_of_digits_after_comma_for_branch_length_values;
106     }
107
108     final short getNumberOfDigitsAfterCommaForConfidenceValues() {
109         return _number_of_digits_after_comma_for_confidence_values;
110     }
111
112     final OVERVIEW_PLACEMENT_TYPE getOvPlacement() {
113         return _ov_placement;
114     }
115
116     final PHYLOGENY_GRAPHICS_TYPE getPhylogenyGraphicsType() {
117         return _phylogeny_graphics_type;
118     }
119
120     final float getPrintLineWidth() {
121         return _print_line_width;
122     }
123
124     final int getPrintSizeX() {
125         return _print_size_x;
126     }
127
128     final int getPrintSizeY() {
129         return _print_size_y;
130     }
131
132     final double getScaleBarLength() {
133         return _scale_bar_length;
134     }
135
136     final private void init() {
137         _default_node_shape = NodeShape.RECTANGLE_WITH_GRADIENT;
138         _show_branch_length_values = false;
139         _internal_number_are_confidence_for_nh_parsing = false;
140         _show_scale = false;
141         _antialias_screen = true;
142         _antialias_print = true;
143         _graphics_export_visible_only = false;
144         _editable = true;
145         _background_color_gradient = false;
146         if ( Util.isUsOrCanada() ) {
147             _print_size_x = Constants.US_LETTER_SIZE_X;
148             _print_size_y = Constants.US_LETTER_SIZE_Y;
149         }
150         else {
151             _print_size_x = Constants.A4_SIZE_X;
152             _print_size_y = Constants.A4_SIZE_Y;
153         }
154         _min_confidence_value = MIN_CONFIDENCE_DEFAULT;
155         _print_black_and_white = false;
156         _print_using_actual_size = false;
157         _graphics_export_using_actual_size = true;
158         _phylogeny_graphics_type = PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR;
159         _base_font = new Font( Configuration.getDefaultFontFamilyName(), Font.PLAIN, 10 );
160         _match_whole_terms_only = false;
161         _search_case_sensitive = false;
162         _print_line_width = Constants.PDF_LINE_WIDTH_DEFAULT;
163         _show_overview = true;
164         _ov_placement = OVERVIEW_PLACEMENT_TYPE.UPPER_LEFT;
165         _node_label_direction = NODE_LABEL_DIRECTION.HORIZONTAL;
166         _inverse_search_result = false;
167         _scale_bar_length = 0.0;
168         _number_of_digits_after_comma_for_branch_length_values = Constants.NUMBER_OF_DIGITS_AFTER_COMMA_FOR_BRANCH_LENGTH_VALUES_DEFAULT;
169         _number_of_digits_after_comma_for_confidence_values = Constants.NUMBER_OF_DIGITS_AFTER_COMMA_FOR_CONFIDENCE_VALUES_DEFAULT;
170         _nh_parsing_replace_underscores = false;
171         _nh_parsing_extract_pfam_taxonomy_codes = false;
172         _cladogram_type = Constants.CLADOGRAM_TYPE_DEFAULT;
173         _show_domain_labels = true;
174         setAbbreviateScientificTaxonNames( false );
175         _color_labels_same_as_parent_branch = false;
176     }
177
178     final boolean isAntialiasPrint() {
179         return _antialias_print;
180     }
181
182     final boolean isAntialiasScreen() {
183         return _antialias_screen;
184     }
185
186     final boolean isBackgroundColorGradient() {
187         return _background_color_gradient;
188     }
189
190     public final boolean isShowDomainLabels() {
191         return _show_domain_labels;
192     }
193
194     final boolean isColorLabelsSameAsParentBranch() {
195         return _color_labels_same_as_parent_branch;
196     }
197
198     final boolean isEditable() {
199         return _editable;
200     }
201
202     final boolean isExtractPfamTaxonomyCodesInNhParsing() {
203         return _nh_parsing_extract_pfam_taxonomy_codes;
204     }
205
206     final boolean isGraphicsExportUsingActualSize() {
207         return _graphics_export_using_actual_size;
208     }
209
210     final boolean isGraphicsExportVisibleOnly() {
211         return _graphics_export_visible_only;
212     }
213
214     final boolean isInternalNumberAreConfidenceForNhParsing() {
215         return _internal_number_are_confidence_for_nh_parsing;
216     }
217
218     final boolean isInverseSearchResult() {
219         return _inverse_search_result;
220     }
221
222     final boolean isMatchWholeTermsOnly() {
223         return _match_whole_terms_only;
224     }
225
226     final boolean isPrintBlackAndWhite() {
227         return _print_black_and_white;
228     }
229
230     final boolean isPrintUsingActualSize() {
231         return _print_using_actual_size;
232     }
233
234     final boolean isReplaceUnderscoresInNhParsing() {
235         return _nh_parsing_replace_underscores;
236     }
237
238     final boolean isSearchCaseSensitive() {
239         return _search_case_sensitive;
240     }
241
242     final boolean isShowBranchLengthValues() {
243         return _show_branch_length_values;
244     }
245
246     final NodeShape getDefaultNodeShape() {
247         return _default_node_shape;
248     }
249
250     final boolean isShowOverview() {
251         return _show_overview;
252     }
253
254     final boolean isShowScale() {
255         return _show_scale;
256     }
257
258     final void setAntialiasPrint( final boolean antialias_print ) {
259         _antialias_print = antialias_print;
260     }
261
262     final void setAntialiasScreen( final boolean antialias_screen ) {
263         _antialias_screen = antialias_screen;
264     }
265
266     public void setBackgroundColorGradient( final boolean background_color_gradient ) {
267         _background_color_gradient = background_color_gradient;
268     }
269
270     public void setShowDomainLabels( final boolean show_domain_labels ) {
271         _show_domain_labels = show_domain_labels;
272     }
273
274     public void setColorLabelsSameAsParentBranch( final boolean color_labels_same_as_parent_branch ) {
275         _color_labels_same_as_parent_branch = color_labels_same_as_parent_branch;
276     }
277
278     final void setBaseFont( final Font base_font ) {
279         _base_font = base_font;
280     }
281
282     final void setCladogramType( final CLADOGRAM_TYPE cladogram_type ) {
283         _cladogram_type = cladogram_type;
284     }
285
286     final void setEditable( final boolean editable ) {
287         _editable = editable;
288     }
289
290     final void setExtractPfamTaxonomyCodesInNhParsing( final boolean nh_parsing_extract_pfam_taxonomy_codes ) {
291         _nh_parsing_extract_pfam_taxonomy_codes = nh_parsing_extract_pfam_taxonomy_codes;
292     }
293
294     final void setGraphicsExportUsingActualSize( final boolean graphics_export_using_actual_size ) {
295         _graphics_export_using_actual_size = graphics_export_using_actual_size;
296         if ( !graphics_export_using_actual_size ) {
297             setGraphicsExportVisibleOnly( false );
298         }
299     }
300
301     final void setGraphicsExportVisibleOnly( final boolean graphics_export_visible_only ) {
302         _graphics_export_visible_only = graphics_export_visible_only;
303         if ( graphics_export_visible_only ) {
304             setGraphicsExportUsingActualSize( true );
305         }
306     }
307
308     final void setInternalNumberAreConfidenceForNhParsing( final boolean internal_number_are_confidence_for_nh_parsing ) {
309         _internal_number_are_confidence_for_nh_parsing = internal_number_are_confidence_for_nh_parsing;
310     }
311
312     final void setInverseSearchResult( final boolean inverse_search_result ) {
313         _inverse_search_result = inverse_search_result;
314     }
315
316     final void setMatchWholeTermsOnly( final boolean search_whole_words_only ) {
317         _match_whole_terms_only = search_whole_words_only;
318     }
319
320     final void setMinConfidenceValue( final double min_confidence_value ) {
321         _min_confidence_value = min_confidence_value;
322     }
323
324     final void setNodeLabelDirection( final NODE_LABEL_DIRECTION node_label_direction ) {
325         _node_label_direction = node_label_direction;
326     }
327
328     final private void setNumberOfDigitsAfterCommaForBranchLength( final short number_of_digits_after_comma_for_branch_length_values ) {
329         _number_of_digits_after_comma_for_branch_length_values = number_of_digits_after_comma_for_branch_length_values;
330     }
331
332     final private void setNumberOfDigitsAfterCommaForConfidenceValues( final short number_of_digits_after_comma_for_confidence_values ) {
333         _number_of_digits_after_comma_for_confidence_values = number_of_digits_after_comma_for_confidence_values;
334     }
335
336     final void setOvPlacement( final OVERVIEW_PLACEMENT_TYPE ov_placement ) {
337         _ov_placement = ov_placement;
338     }
339
340     final void setPhylogenyGraphicsType( final PHYLOGENY_GRAPHICS_TYPE phylogeny_graphics_type ) {
341         _phylogeny_graphics_type = phylogeny_graphics_type;
342     }
343
344     final void setPrintBlackAndWhite( final boolean print_black_and_white ) {
345         _print_black_and_white = print_black_and_white;
346     }
347
348     final void setPrintLineWidth( final float print_line_width ) {
349         _print_line_width = print_line_width;
350     }
351
352     final void setPrintSizeX( final int print_size_x ) {
353         _print_size_x = print_size_x;
354     }
355
356     final void setPrintSizeY( final int print_size_y ) {
357         _print_size_y = print_size_y;
358     }
359
360     final void setPrintUsingActualSize( final boolean print_using_actual_size ) {
361         _print_using_actual_size = print_using_actual_size;
362     }
363
364     final void setReplaceUnderscoresInNhParsing( final boolean nh_parsing_replace_underscores ) {
365         _nh_parsing_replace_underscores = nh_parsing_replace_underscores;
366     }
367
368     final void setScaleBarLength( final double scale_bar_length ) {
369         _scale_bar_length = scale_bar_length;
370     }
371
372     final void setSearchCaseSensitive( final boolean search_case_sensitive ) {
373         _search_case_sensitive = search_case_sensitive;
374     }
375
376     final void setShowBranchLengthValues( final boolean show_branch_length_values ) {
377         _show_branch_length_values = show_branch_length_values;
378     }
379
380     final void setDefaultNodeShape( final NodeShape default_node_shape ) {
381         _default_node_shape = default_node_shape;
382     }
383
384     final void setShowOverview( final boolean show_overview ) {
385         _show_overview = show_overview;
386     }
387
388     final void setShowScale( final boolean show_scale ) {
389         _show_scale = show_scale;
390     }
391
392     final static Options createDefaultInstance() {
393         return new Options();
394     }
395
396     final static Options createInstance( final Configuration configuration ) {
397         final Options instance = createDefaultInstance();
398         if ( configuration != null ) {
399             instance.setAntialiasScreen( configuration.isAntialiasScreen() );
400             instance.setShowScale( configuration.isShowScale() );
401             instance.setShowBranchLengthValues( configuration.isShowBranchLengthValues() );
402             instance.setShowOverview( configuration.isShowOverview() );
403             instance.setCladogramType( configuration.getCladogramType() );
404             instance.setOvPlacement( configuration.getOvPlacement() );
405             instance.setPrintLineWidth( configuration.getPrintLineWidth() );
406             instance.setNodeLabelDirection( configuration.getNodeLabelDirection() );
407             instance.setBackgroundColorGradient( configuration.isBackgroundColorGradient() );
408             if ( configuration.getNumberOfDigitsAfterCommaForBranchLengthValues() >= 0 ) {
409                 instance.setNumberOfDigitsAfterCommaForBranchLength( configuration
410                         .getNumberOfDigitsAfterCommaForBranchLengthValues() );
411             }
412             if ( configuration.getNumberOfDigitsAfterCommaForConfidenceValues() >= 0 ) {
413                 instance.setNumberOfDigitsAfterCommaForConfidenceValues( configuration
414                         .getNumberOfDigitsAfterCommaForConfidenceValues() );
415             }
416             instance.setExtractPfamTaxonomyCodesInNhParsing( configuration.isExtractPfamTaxonomyCodesInNhParsing() );
417             instance.setReplaceUnderscoresInNhParsing( configuration.isReplaceUnderscoresInNhParsing() );
418             instance.setInternalNumberAreConfidenceForNhParsing( configuration
419                     .isInternalNumberAreConfidenceForNhParsing() );
420             instance.setEditable( configuration.isEditable() );
421             instance.setColorLabelsSameAsParentBranch( configuration.isColorLabelsSameAsParentBranch() );
422             instance.setShowDomainLabels( configuration.isShowDomainLabels() );
423             instance.setAbbreviateScientificTaxonNames( configuration.isAbbreviateScientificTaxonNames() );
424             if ( configuration.getMinConfidenceValue() != MIN_CONFIDENCE_DEFAULT ) {
425                 instance.setMinConfidenceValue( configuration.getMinConfidenceValue() );
426             }
427             if ( configuration.getGraphicsExportX() > 0 ) {
428                 instance.setPrintSizeX( configuration.getGraphicsExportX() );
429             }
430             if ( configuration.getGraphicsExportY() > 0 ) {
431                 instance.setPrintSizeY( configuration.getGraphicsExportY() );
432             }
433             if ( configuration.getBaseFontSize() > 0 ) {
434                 instance.setBaseFont( instance.getBaseFont().deriveFont( ( float ) configuration.getBaseFontSize() ) );
435             }
436             if ( !ForesterUtil.isEmpty( configuration.getBaseFontFamilyName() ) ) {
437                 instance.setBaseFont( new Font( configuration.getBaseFontFamilyName(), Font.PLAIN, instance
438                         .getBaseFont().getSize() ) );
439             }
440             if ( configuration.getPhylogenyGraphicsType() != null ) {
441                 instance.setPhylogenyGraphicsType( configuration.getPhylogenyGraphicsType() );
442             }
443         }
444         return instance;
445     }
446
447     final void setAbbreviateScientificTaxonNames( final boolean abbreviate_scientific_names ) {
448         _abbreviate_scientific_names = abbreviate_scientific_names;
449     }
450
451     final boolean isAbbreviateScientificTaxonNames() {
452         return _abbreviate_scientific_names;
453     }
454
455     static enum CLADOGRAM_TYPE {
456         NON_LINED_UP, EXT_NODE_SUM_DEP, TOTAL_NODE_SUM_DEP;
457     }
458
459     static enum NODE_LABEL_DIRECTION {
460         HORIZONTAL, RADIAL;
461     }
462
463     static enum OVERVIEW_PLACEMENT_TYPE {
464         UPPER_LEFT( "upper left" ),
465         UPPER_RIGHT( "upper right" ),
466         LOWER_LEFT( "lower left" ),
467         LOWER_RIGHT( "lower right" );
468
469         private final String _name;
470
471         private OVERVIEW_PLACEMENT_TYPE( final String name ) {
472             _name = name;
473         }
474
475         @Override
476         public String toString() {
477             return _name;
478         }
479
480         public String toTag() {
481             return toString().replaceAll( " ", "_" );
482         }
483     }
484
485     static enum PHYLOGENY_GRAPHICS_TYPE {
486         RECTANGULAR, TRIANGULAR, EURO_STYLE, ROUNDED, CONVEX, CURVED, UNROOTED, CIRCULAR;
487     }
488
489     boolean isAllowMagnificationOfTaxonomyImages() {
490         return true;
491     }
492
493     int getDefaultNodeBoxSize() {
494         // TODO make variable ~~
495         return 8;
496     }
497 }