##### Example 1: TestDesignInvoice.java

TestDesignInvoice.java is primarily designed for creating a report with the methods provided by the Designer API. Here is an explanation of how TestDesignInvoice.java works.

- Creating an instance of Designer
  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.

- Setting log if necessary
  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.

- Getting handles
  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.

- Creating a report
  report = desg.create(name, "invoice");

  This method creates a new report and returns its handle. Parameter name is the name of the report that is to be created, and Invoice is the name of the query in the catalog file SampleReports.cat with which the report is created.

- Inserting a group panel
  group = desg.insert(handles[0], Designer.GROUP, "GroupPanel1", "Customers_Customer ID");

  This method inserts a new group panel and returns its handle. Parameter handle[0] is the parent node handle. The newly inserted object will be in this node. Designer.GROUP is the class type for this type of insertion. GroupPanel1 is the name of group panel that is to be inserted, and Customers_Customer ID is the mapping name to group by.

- Inserting a label
  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.

- Inserting DBField
  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.

- Inserting a formula, parameter and summary
  To insert a formula, parameter or summary, use the same method as for inserting a DBField. Note that the formula, parameter or summary that is to be inserted should already exist in the catalog.

  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");

- Inserting an image, box and line
  To insert an image, box or line, use the same method as for inserting a label.

  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");

- Setting the property value
  To set the property value, you should provide three parameters: object handle, property name and property value.

  In the sample program, you can set the property value as follows:

      desg.set(handle, "Width", 1.74f);
      desg.set(handle, "Height", 0.35f);
      desg.set(handle, "Text", "Invoice");
      desg.set(handle, "Alignment", desg.LEFTCENTER);
      desg.set(handle, "Foreground", new Color(0x900000));
      desg.set(handle, "Bold", true);
      desg.set(handle, "FontSize", 0.31f);

- Exiting and closing all reports
  desg.exit();

  This method ends the editing status, releases all resources and saves all of the reports and the catalog.

- Compiling and running the sample program
  To compile and run the sample program, you should add report.jar, sac.jar and JREngine.jar with their path into the class path. And it is assumed that TestCatalogAPI.java in `C:\JReport\Designer\help\designer\samples` has been run first to generate a catalog file Tutorial.cat in `C:\JReport\Designer\Demo\Reports\APITutorial`.

  For example, you can use the following command to compile the sample program:

      C:\JReport\Designer\help\designer\samples>javac
      -classpath "C:\JReport\Designer\lib\report.jar;C:\JReport\Designer\lib\sac.jar;
      C:\JReport\Designer\lib\JREngine.jar"
      TestDesignInvoice.java

  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:

      C:\JReport\Designer\help\designer\samples>java
      -Dreporthome="C:\JReport\Designer"
      -classpath "C:\JReport\Designer\lib\jrengine.jar;C:\JReport\Designer\lib\sac.jar;
      C:\JReport\Designer\lib\resource.jar;C:\JReport\Designer\lib\report.jar;
      C:\JReport\Designer\lib\log4j-1.2.8.jar;C:\JReport\Designer\lib\hsqldb.jar"
      TestDesignInvoice C:\JReport\Designer\Demo\Reports\APITutorial Tutorial.cat

  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:

      C:\JReport\Designer\help\designer\samples>java -Dreporthome="C:\JReport\Designer"
      -classpath "C:\JReport\Designer\lib\JREngine.jar;C:\JReport\Designer\lib\sac.jar;
      C:\JReport\Designer\lib\resource.jar;C:\JReport\Designer\lib\report.jar;
      C:\JReport\Designer\lib\log4j-1.2.8.jar;C:\JReport\Designer\lib\hsqldb.jar"
      TestDesignInvoice C:\JReport\Designer\Demo\Reports\APITutorial Tutorial.cat
      C:\test\log.txt

  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\designer\samples` (location of the sample programs). After running the program, you will find a newly created file invoice1.cls in `C:\JReport\Designer\Demo\Reports\APITurorial`.