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