TestDesignInvoice.java in <insatll_root>\help\samples\APIDesign
is primarily designed for creating a report with the methods provided by the Design API. Here is an explanation of how TestDesignInvoice.java works.
desg = new Designer(path, cat);
The constructor of Designer has two parameters: path and name. They are respectively the path and name of the catalog with which the report will be created.
desg.setLog(new FileOutputStream(log), "8859_1");
The output stream log points to the path and file in which to write log messages. Parameter "8859_1" is the encoding for the messages.
handles = desg.getHandles(report, Designer.PAGE);
This method gets all handles of PAGE type and returns a handle array. Parameter report is the parent handle, and Designer.PAGE is a class type value which is defined in the Designer class.
This method creates a new report and returns its handle. Parameter name is the name of the report that is to be created.
// Register the existing query "WorldWideSales" to this report set.
dataset = designer.addDataset(reportset, "Data Source 1", "WorldWideSales","dsWorldWideSales", "",Designer.DATASET_TYPE_QUERY);
This method adds a dataset to the report. The dataset must exist in the referenced catalog.
// Add a report tab named "Invoice" to the report set.
report = designer.addReport(reportset, "Invoice");
This method creates a new report and returns its handle. Parameter name is the name of the report that is to be created.
// Insert the banded object for the invoice report
banded = designer.insertBandedObject(reportbody, true, true, true);
This method adds a banded object into our report tab.
gGroupInfo ginfo =new GroupInfo( "Customers_Customer ID", GroupInfo.DESCENDING );
groupCust = designer.insertSectionGroup( handles[0], ginfo );
This method inserts a new group panel and returns its handle. Parameter handles[0] is the parent node handle. The newly inserted object will be in this node. Customers_Customer ID is the mapping name to group by.
handle = desg.insert(header, Designer.LABEL, "Label1");
This method inserts a label named label1 into the group header. Parameter header is the parent handle, the newly inserted object will be in this node. desg.LABEL is the class type that you want to insert, and Label1 is the object name to be inserted.
handle = desg.insert(header, Designer.DBFIELD, "DBField1", "Orders_Order ID");
This method inserts a DBField named DBField1 into the group header. Parameter header is handle of the parent node; Designer.DBFIELD is class type that is to be inserted, and Orders_Orders ID is the mapping name of the database field.
For example, in the sample program, it is made sure that the parameter PToday, formula customeraddress12, and summary Sum_total9 already exist in the catalog by the following:
handle = desg.insert(header, Designer.PARAMETER, "Parameter1", "PToday");
handle = desg.insert(header, Designer.FORMULA, "formula1", "customeraddress12");
handle = desg.insert(footer, Designer.SUMMARY, "summary1", "Sum_total9");
For example, in the sample program, you can insert the image, box and line as follows:
handle = desg.insert(header, Designer.IMAGE, "Image1");
handle = desg.insert(report, Designer.BOX, "Box1");
handle = desg.insert(report, Designer.LINE, "Line1");
In the sample program, you can set the property value as follows:
|
desg.exit();
This method ends the editing status, releases all resources and saves all of the reports and the catalog.
For example, you can use the following command to compile the sample program:
|
When you run the sample program, you should provide two or three parameters. If you want to use two parameters, they should be catalog path and catalog name, and the command line should be:
|
If you want to use three parameters, they should be catalog path, catalog name and log file with a full path name, and the command line should be:
|
Here, it is assumed that JReport Designer has been installed to C:\JReport\Designer
, and the current directory when you execute these commands is C:\JReport\Designer\help\samples\APIDesign
(location of the sample programs). After running the program, you will find a newly created file TestInvoice.cls in C:\JReport\Designer\Demo\Reports\TutorialReports
.