Card demo

An internet cafe provides several payment models for their customers. Whenever a user pays for an account, he gets a printed card with the account details and can use the data on these cards to login to the systems.

There are several card types available:

This demo simulates the printing functionality of that internet cafe management software.

Data structure

All cards that should be printed get added to the CardTableModel. That model is a union over all possible properties each available card may have. The first column contains the card type identifier. Columns not used by the given card type remain empty (null).

We want to print two cards in a row. JFreeReport's code assumes, that each row in the tablemodel is mapped to an item band in the report. We are having a single card per row, so we have to modify the tablemodel to map two cards to a row.

For that purpose, we introduced a 'WrappingTablemodel', which performs that mapping. Two rows of the original tablemodel get mapped into a single row of the WrappingTableModel. The first and all odd-numbered rows of the original tablemodel form the left side of the table. All these columns are prefixed with a 'C1_'. All even numbered rows form the right side of the resulting table and all columns there are prefixed with 'C2_'.

Report Layout

The itemband will have to double all elements as we have to print the cards for the left (C1_) and right (C2_) side of the table. For each card type, a subband will be used, which is triggered visible or invisible depending on the card type to be printed.

The report uses the extended XML configuration. First, we define the styles for all report elements in the 'style' section. This reduces the redundancy of the report definition, as we can use shared styles.

In a second step, we define the 'templates' for the band elements. Templates define, how data is processed for the output. As we are mostly using string fields, the templates of this report are rather simple. The 'simple-datefield' template defined in this report shows how templates could be used to reduce the redundancy of the data definition in a similiar fashion as it was done with the style definitions above.

Finally we construct the itemband (the only root level band in this report). The itemband contains two direct childs, a band for the left and one for the right card. In each of these child bands, exactly the same subband definitions get used. Each element definition there consists of a single style definition and a single template definition, inheriting their properties from the global definition sections.

Functions

To control the visibility of the band, a special function is used. The 'SelectCardFunction' uses the specified card type column to trigger the visiblity of the card bands. Two instances of this function get used, one for the left side and one for the right side of the itemband.

The report properties used to define the internet cafe's name are initialized with default values.