JIDE 3.5.15

com.jidesoft.grid
Class TableScrollPanePrintable

java.lang.Object
  extended by com.jidesoft.grid.TableScrollPanePrintable
All Implemented Interfaces:
Printable

public class TableScrollPanePrintable
extends Object
implements Printable

An implementation of Printable for printing TableScrollPanes.

This implementation spreads TableScrollPane rows naturally in sequence across multiple pages, fitting as many rows as possible per page. The distribution of columns, on the other hand, is controlled by a printing mode parameter passed to the constructor. When JTable.PrintMode.NORMAL is used, the implementation handles columns in a similar manner to how it handles rows, spreading them across multiple pages (in an order consistent with the TableScrollPane's ComponentOrientation). When JTable.PrintMode.FIT_WIDTH is given, the implementation scales the output smaller if necessary, to ensure that all columns fit on the page. (Note that width and height are scaled equally, ensuring that the aspect ratio remains the same).

The portion of table printed on each page is headed by the appropriate section of the table's JTableHeader.

Header and footer text can be added to the output by providing MessageFormat instances to the constructor. The printing code requests Strings from the formats by calling their format method with a single parameter: an Object array containing a single element of type Integer, representing the current page number.

There are certain circumstances where this Printable cannot fit items appropriately, resulting in clipped output. These are:

It is entirely valid for a developer to wrap this Printable inside another in order to create complex reports and documents. They may even request that different pages be rendered into different sized printable areas. The implementation was designed to handle this by performing most of its calculations on the fly. However, providing different sizes works best when JTable.PrintMode.FIT_WIDTH is used, or when only the printable width is changed between pages. This is because when it is printing a set of rows in JTable.PrintMode.NORMAL and the implementation determines a need to distribute columns across pages, it assumes that all of those rows will fit on each subsequent page needed to fit the columns.

It is the responsibility of the developer to ensure that the table is not modified in any way after this Printable is created (invalid modifications include changes in: size, renderers, or underlying data). The behavior of this Printable is undefined if the table is changed at any time after creation.


Field Summary
 
Fields inherited from interface java.awt.print.Printable
NO_SUCH_PAGE, PAGE_EXISTS
 
Constructor Summary
TableScrollPanePrintable(TableScrollPane tableScrollPane, JTable.PrintMode printMode, MessageFormat headerFormat, MessageFormat footerFormat)
          Create a new TablePrintable for the given TableScrollPane.
 
Method Summary
 int print(Graphics graphics, PageFormat pageFormat, int pageIndex)
          Prints the specified page of the table into the given Graphics context, in the specified format.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TableScrollPanePrintable

public TableScrollPanePrintable(TableScrollPane tableScrollPane,
                                JTable.PrintMode printMode,
                                MessageFormat headerFormat,
                                MessageFormat footerFormat)
Create a new TablePrintable for the given TableScrollPane. Header and footer text can be specified using the two MessageFormat parameters. When called upon to provide a String, each format is given the current page number.

Parameters:
tableScrollPane - the table to print
printMode - the printing mode for this printable
headerFormat - a MessageFormat specifying the text to be used in printing a header, or null for none
footerFormat - a MessageFormat specifying the text to be used in printing a footer, or null for none
Throws:
IllegalArgumentException - if passed an invalid print mode
Method Detail

print

public int print(Graphics graphics,
                 PageFormat pageFormat,
                 int pageIndex)
          throws PrinterException
Prints the specified page of the table into the given Graphics context, in the specified format.

Specified by:
print in interface Printable
Parameters:
graphics - the context into which the page is drawn
pageFormat - the size and orientation of the page being drawn
pageIndex - the zero based index of the page to be drawn
Returns:
PAGE_EXISTS if the page is rendered successfully, or NO_SUCH_PAGE if a non-existent page index is specified
Throws:
PrinterException - if an error causes printing to be aborted

JIDE 3.5.15