#1 Ranking: Read how InetSoft was rated #1 for user adoption in G2's user survey-based index |
|
Read More |
Printing Tables
There are two implementations for a ReportSheet: a StyleSheet or a TabularSheet. The StyleSheet represents the
flow based layout model and a TabularSheet represents the tabular grid based layout model. The next step is to
cast the ReportSheet to a TabularSheet or a StyleSheet depending on whether you wish to have a tabular or flow
based layout method.
StyleSheet layout = new StyleSheet();
The report is empty when it is first created. You must add document elements to the report to set up the
report. Elements accepted by the report include table, chart, image, text and more.
To add a table to the report, we first need to obtain a TableLens object. Assuming a Swing JTable is displayed
on screen, you can simply use the Swing table adapter in the inetsoft.report.lens.swing package to get a
TableLens object:
layout.addTable(new JTableLens(jtable));
A table lens is a generic interface for defining the data source for tabular data. In this example, we use an
on-screen table as the data source. It is just as easy to create a data source from databases or second-tier
servers. Since the focus of this document is report formatting and layout, we will use on-screen tables in these
examples and will briefly review the steps for creating other data feeds later.
To print the report, simply call the print() method in the ReportSheet.
report.print();
If we are exporting the report to another format, or using the custom driver, we get a java.awt.PrintJob and
then print the report. The export classes and the custom driver provide methods to get the PrintJob.
PrintJob job = ...; Report.print(job);
These two lines of code will cause a report that contains the same table on the screen to be printed. This is
the simplest form of using Style Intelligence to generate printed copies of tables.
Example: Printing JTable
We are going to use this example as the base and add more advanced styles and features to create a complete
report example.
Listing 7. Printing JTable (Report1.java)
import java.awt.*;
import java.util.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.table.*;
import inetsoft.report.*;
import inetsoft.report.lens.swing.*;
/**
* This example shows how to print a JTable (swing).
*
* @version 1.2.12.1, 5/26/2009
* @author InetSoft Technology Corp
*/
public class Report1 extends Frame {
public Report1() {
super("JTable Report");
final String header[] =
{"Company","Close","P/E","Yield", "ROE"};
final String[][] data = {
{"ADE CORPORATION", "8.38", "13.7", "0.0", "4.8"},
{"AEHR TEST SYSTEMS", "3.63", "10.1", "0.0", "6.0"},
{"AG ASSOCIATES INC", "2.75", "NE", "0.0", "NE"},
...
{"RELIABILITY INC", "4.47", "3.3", "0.0", "39.3"},
{"SEMITOOL INC", "6.44", "8.9", "0.0", "15.3"},
};
// create testing data
TableModel model = new AbstractTableModel() {
public Object getValueAt(int r, int c) {
if (r >= data.length) {
return null;
}
if (c >= data[r].length) {
return null;
}
return data[r][c];
}
public int getRowCount() { return data.length; }
public int getColumnCount() { return data[0].length; }
public String getColumnName(int c) { return header[c]; }
public Class getColumnClass(int c) {return String.class;}
};
table = new JTable(model);
add(new JScrollPane(table), "Center");
Panel pnl = new Panel();
add(pnl, "South");
Button printB = new Button("Print");
pnl.add(printB);
printB.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
ReportSheet report = createReport();
try {
report.print();
}
catch(Exception x) {}
}
});
Button quitB = new Button("Quit");
pnl.add(quitB);
quitB.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.exit(0);
}
});
}
public ReportSheet createReport() {
StyleSheet layout = new StyleSheet();
// create a table lens
JTableLens lens = new JTableLens(table);
layout.addTable(lens);
return layout;
}
private JTable table;
public static void main(String[] args) {
ReportEnv.setProperty("StyleReport.useCustomDriver", "true");
Report1 win = new Report1();
win.pack();
win.setVisible(true);
}
}
More Articles About Reporting APIs
InetSoft's Approach to KBMs - All companies, whether selling products or services, need to track their key business metrics. This screenshot shows an example dashboard created in the InetSoft Style Intelligence application. Using the point-and-click interface, this dashboard tracks several very important performance indicators and presents them all in real time to the end-user...
Notes on Report Permissions - The 'Use Parent Permissions' option for a report or a folder implies that it will inherit all of the permissions from its parent folder. If there are no permissions set for its immediate parent, its permission inheritance will recurse higher up in the hierarchy of folders, until the root folder is reached...
Transparency Of Decision Making - Because you can, as a senior manager, see by virtue of looking down a layer of dashboards, what people are doing, what decisions they have been making and when. That gives you a lot of ability to understand what is happening. Indeed, a lot of things have changed in the past ten years in the whole BI and dashboard space. One of the biggest things we are seeing and are very excited about, because it aligns well with our strategy, is the idea is that the KPIs and business metrics can really escape the upper echelon of the organization and be applicable to the entire hierarchy of an organization...
Use Maps in an Interactive Dashboard - InetSoft's interactive dashboard solution allows you to customize the way your data is displayed in map to give you maximum self-service in data exploration. View the example here to learn how InetSoft's Style Intelligence can help your business analyze performance. You can interactively explore a map in Visual Composer using tools such as Zoom, Pan, and Pick. When you save the Viewsheet, the current state of the map is also saved, and this determines the initial view for the end-user. There are two basic ways to manipulate the map, by using the Control Panel, and by clicking and dragging on the map itself. These methods are described below...