JasperReports styles in JasperWave
JasperReports styles in JasperWave
Join the DZone community and get the full member experience.Join For Free
Introduction to JasperReports styles
JasperReports provides the concept of report style. Style in JasperReports is actually the subset of all the report element properties that can be defined in report template. Every report element like rectangle, text element, image, chart and others can be associated with report style. There are several main use-cases of what property value is taken from where based on different criteria. But before diving into these rules we need to understand what does it mean default style. If any style (internal or external) marked as default - it means that the style will be applied to all the report elements in report template without explicitly associated with them. So don't be surprised if report element look and feel is different from its default one - check if there is default style defined. But with JasperWave everything will be easy and transparent - you will see immediately where property value is taken from. Will see it soon...
Let's first describe the cases:
- UC1. Property default value - No style assigned (explicitly or by default style). The default property value will be applied.
- UC2. Property non-default value - No style assigned (explicitly or by default style). Overridden (non-default) property value will be applied.
- UC3. Property default value - Style assigned (explicitly or by default style). The style property value (if defined in the style) will be applied.
- UC4. Property non-default value - Style assigned (explicitly or by default style). Overridden (non-default) property value will be applied even if the property is defined in style. So the property non-default value has the highest priority.
Explicitly means that style is associated with report element by defining corresponding property of report element. The goal of this tutorial is not to describe in details the JasperReports styles approach and use - so please refer to JasperReports official documentation if you are not familiar enough with JasperReports reporting engine and styles there.
For now just try to remember the cases above and understand what everyone means.
Internal and external styles
Every style can defined and saved in two different let's call it locations: report template and style template. Let's further call the first style internal and second one external.
Internal styles are saved in the same report template definition file and can be used in one report template only. External styles are defined and saved in special style template file. Then these style templates can be associated with any report template and styles defined there can be applied on report elements inside report template.
It is possible to associate several style templates with one report template in two ways:
- Directly. Several style templates are connected with report template by explicitly adding references from report template to style templates.
- Indirectly. Style template can have reference to another style template. So by adding reference to style template that itself has reference to another style template you will have report template associated with several style templates.
Here is the concepts. For details please refer to JasperReports documentation. Especially it will be helpful to look at JasperReport official report template example StylesReport.jrxml and associated style templates styles.jrtx and base_styles.jrtx.
What is very important to know about styles in JasperReports is that styles are organized in hierarchy way. It means that every style can have parent style. For simplicity lets take a look at JasperReport official report template example StylesReport.jrxml and associated style templates styles.jrtx andbase_styles.jrtx:
There are several important points that you should understand and remember from the hierarchy above:
- Styles hierarchy is constructed without taking into account if the style is internal or external. In the example above the style are defined internally and externally inside two style templates
- Styles inheritance. It means that if the Very Strong (base_style.jrtx) style will be assigned to report elements then the property values will try to be resolved Very Strong (base_style.jrtx) - Strong (base_style.jrtx) - Base (base_style.jrtx) according to the tree structure.
- Internal style has higher priority over external one with the same name. In our case we have Serif Note style defined both internally and insidestyles.jrtx style template.
The example above shows most of JasperReports styles features but it is too complicated to be a real life example. So it is not recommended to repeat it - try to design hierarchy and location of styles as simple as possible.
Styles management in JasperWave
The section presents the way JasperWave works with JasperReports styles. The goal was to provide transparent and intuitive solution by improving JasperWave properties framework, style management dialog and connect them to each other. On the next sections all the details of this approach will be presented. Also several special cases will be explained to help you understand JasperReports styles more deeply.
Read the rest of article here: http://jasperwave.com/docs/styles.html
Opinions expressed by DZone contributors are their own.