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