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