Java2D Based Print Previewer

It is often desirable to allow users to preview what is going to be printed before actually sending it to the printer. The previewing capability has become standard on most applications. Style Intelligence has built-in support for easily adding previewing to an application. A Java2 based previewer provides support for Java2 printing API.


BI DemoRegister
dashboard example

Creating a Previewer

A previewer can be created in a number of ways. The preferred method is through the Previewer.createPreviewer() method.

Adding previewing support to an application is as simple as creating a previewer and calling the print() method of the previewer to show a report.

 ReportSheet report = createReport();
 PreviewView previewer = Previewer.createPreviewer();
 previewer.print(report); 

Once a previewer is created and populated, simply show the window as any other window.

 previewer.pack(); previewer.setVisible(true); 

Scaling the Preview

By default, when a previewer is first displayed, it displays the pages in 100% view. No scaling is performed. A program can programmatically control the zooming of the preview window by calling the zoom() method.

 // scale to fit the entire page in window
 previewer.zoom(PreviewPane.WHOLE_PAGE); 

Adding a Preview Panel

A PreviewPane can be used to create a panel that can be added to other containers. It contains the area where the pages are shown, excluding the toolbar. It can be used in ways similar to the Previewer but cannot be shown by itself.

 PreviewPane preview = new PreviewPane();
 preview.print(report);
 add(preview, "Center"); 

Example: Print Preview
In the next example, we change the previous example report so that it provides a preview instead of directly printing.

Listing 8. Printing with Preview (Report2.java)

Class Report2 extends Frame {
   ...
   Button printB = new Button("Preview");
   pnl.add(printB);
   printB.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
         ReportSheet report = createReport();
         PreviewView previewer =
            Previewer.createPreviewer();
         previewer.pack();
         previewer.setVisible(true);
          previewer.print(report);
      }
   });
   ...
   public static void main(String[] args) {
     ReportEnv.setProperty("StyleReport.useCustomDriver",
             "true");
        Report2 win = new Report2();
        win.pack();
        win.setVisible(true);
   }
}

Note that the only difference between Report1 and Report2 is the printing action handler. To an application, the previewer is similar to a printer. The Previewer manages the entire previewing action and no additional code is necessary in the application.

More Articles About Reporting

Example of a Step Line Chart - This dual axis chart from the Power Management Dashboard illustrates how a Step Line Chart is, in many cases, more "honest" than a regular Line Chart. This Step Line Chart contains two stepped lines, one representing solar panel installations and the other total output from solar panels. Both of these are non-continuous, in that they may change drastically from one quarter to another without going through an smooth transition from one amount to the other. Step Line Chart Example If this were a Line Chart, the lines between the data points would imply that there was a daily increase or decrease from one quarter's data point to the next, even though this might not be and often is not the case. Using the Step Line format presents the data points and only the data points, with no false implications in between them...

Free Visualization Software for Visual Analysis - If you're looking for free visualization software to perform data mining or explore your data with an easy to use visual analysis tool, try Visualize Free. Derived from our commercial business intelligence software, this free analytics application is designed to be very intuitive and interactive. How a Free Visualization Tool Can Help Visualization is the perfect technique for sifting through multi-dimensional data to spot trends and aberrations or slice and dice data with simple point-and-click methods...

Good Multi-tenant Dashboard Reporting - In certain deployment scenarios, you may need to provide different groups of users (i.e., "tenants") with access to different sets of data. This is called a multi-tenant environment. For example, if you are serving user groups from different departments or organizations, you may need to give each tenant access to data stored in a unique database or schema (different login permissions, etc.). To facilitate design of a multi-tenant environment, Style Intelligence allows you to define independent data connections for each tenant. Each tenant can access only the unique connections for which they have privileges. Additionally, you can define a common set of data that is accessible to all tenants...

KPIs for EHR Analysts - System uptime, which calculates the proportion of time the EHR system is completely functional, is one of the most important KPIs for EHR analysts. Downtime may cause patient care to be disrupted, which can have serious repercussions. To guarantee constant access to patient information, EHR analysts keep an eye on uptime and work to enhance it. System Response Time Another critical KPI is how quickly the EHR system reacts to user inputs. Inefficient response times might make healthcare professionals impatient and reduce their productivity. To provide a smooth user experience, EHR experts examine response times and try to enhance system performance...

Performance Charts for Executives - For an example of what you want to do, measure executives on three types of measures: people, service, and profit, and you have to make all three green in order to get a good bonus. So what that does is it focuses us on balance; taking care of the customers, taking care of their employees and taking care of their shareholders. So that's going to end up driving the right behavior more so than just looking at financial measures...

Tool to Generate Automatic Reports - Automatic reports are vital for the monitoring and control of business conditions. Without robust report automation tools, the production of regular reports puts additional demands on administrators and employees. With so much business travel and work done out in the field, report accessibly and deliverability can also be an issue. InetSoft's automated reporting tool, Style Report, makes the setup and generation of automated reports easy and efficient...

Previous: Java API-Based Printing