InetSoft Product Information: Changing Report Table Attributes

For table adapters, table attributes are extracted from the table source. Some default values are supplied when an attribute is not available in the table source. In the case of table styles, each style class defines the attributes for that table style. If the attributes supplied by default in these two cases meet the application's needs, there are no further steps needed to set the table look and feel. However, it is often necessary to change some of the default attribute values to meet specific requirements.

The simplest way to change individual table attributes is to use the AttributeTableLens class. The AttributeTableLens API contains methods to change each table's attributes. Because AttributeTableLens is the base class for all table adapters and table styles, its API can be used directly in most cases.

For table lens classes that are not subclasses of AttributeTableLens, an AttributeTableLens can be created as:


 TableLens table = …;
 AttributeTableLens attr = new AttributeTableLens(table);
 attr.setColAlignment(1, StyleConstants.H_RIGHT);
 layout.addTable(attr); 
view demo icon
View a 2-minute demonstration of InetSoft's easy, agile, and robust BI software.

Another way to change the table attributes is to subclass a TableLens class and override the attribute getter methods. This requires slightly more work but is more efficient than the AttributeTableLens.

Landscape Printing

Landscape printing mode is often used to print reports with wide tables. Landscape printing is fully supported by InetSoft products, including all custom printer drivers.

Java2 Landscape Printing

The Java2 printing model requires the page format to be set when creating a print job. Therefore, you must set the correct page format separately. If the application knows the size of the paper and mode, the page format can be hardcoded by creating a PageFormat object by hand. Otherwise, the application can obtain a PageFormat object with the pageDialog() method in the PrinterJob:

 PrinterJob job = StylePrinter.getPrinterJob();
 PageFormat fmt = job.pageDialog(); 

The Java2 page format dialog has portrait and landscape reversed. Check the visual page on top of the dialog to see the correct printing mode.

The user is responsible to select the correct paper and printing mode in the page format dialog. Once a correct PageFormat object is created, it can be used to create a Pageable object using the inetsoft.report.j2d.StyleBook class.

 StyleBook book = new StyleBook(report, fmt);
 job.setPageable(book);
 if(job.printDialog()) {
 job.print();
 }
view gallery
View live interactive examples in InetSoft's dashboard and visualization gallery.

Example: Landscape Printing

The following is an example using Java2 API to print in landscape mode. It uses a page format dialog to allow the user to select the printing mode.

Listing 9. Printing mode selection in Java2 (Landscape1_2.java)

printB.addActionListener(new ActionListener() {
   public void actionPerformed(ActionEvent e) {
      PrinterJob job = StylePrinter.getPrinterJob();
      PageFormat fmt = job.pageDialog(job.defaultPage());
      ReportSheet report = createReport();
      StyleBook book = new StyleBook(report, fmt);

      job.setPageable(book);
      if(job.printDialog()) {
         try {
            job.print();
         } catch(Exception ex) {
            ex.printStackTrace();
         }
      }
   }
});

When using Previewer to view and print a report, the paper size needs to be passed to the Previewer when it is created. The orientation is passed directly from the ReportSheet object. This means that the end user does not need to select landscape-printing mode explicitly in the print dialog.

Note: The Java2 drivers implement landscape printing differently. When orientation is set to landscape, the Java2 printer drivers rotate the printing internally and always assume the printer is in portrait mode. The printer MUST be in PORTRAIT mode for landscape to work properly.

top ranked BI
Read how InetSoft was rated as a top BI vendor in G2 Crowd's user survey-based index.

The following example shows this process.

Listing 10. Landscape printing through previewer (Landscape.java)

public static void main(String[] args) {
ReportEnv.setProperty("StyleReport.useCustomDriver",
"true");
ReportSheet report = createReport();
PreviewView previewer = Previewer.createPreviewer();
previewer.setExitOnClose(true);
 
double w = previewer.getPageWidth();
double h = previewer.getPageHeight();
previewer.setPageWidth(h);
previewer.setPageHeight(w);
report.setOrientation(StyleConstants.LANDSCAPE);
previewer.pack();
previewer.setVisible(true);
previewer.print(report);
}

The landscape printing method is slightly different from that of previous versions of Style Intelligence, which used page sizes to control the printing without regard for orientation settings. In the new approach, users are no longer required to set the printing mode manually.