com.jidesoft.grid
Class TableScrollPanePrintable
java.lang.Object
com.jidesoft.grid.TableScrollPanePrintable
- All Implemented Interfaces:
- Printable
public class TableScrollPanePrintable
- extends Object
- implements Printable
An implementation of Printable
for printing
TableScrollPane
s.
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:
- In any mode, when the header or footer text is too wide to
fit completely in the printable area. The implementation
prints as much of the text as possible starting from the beginning,
as determined by the table's
ComponentOrientation
.
- In any mode, when a row is too tall to fit in the
printable area. The upper most portion of the row
is printed and no lower border is shown.
- In
JTable.PrintMode.NORMAL
when a column
is too wide to fit in the printable area. The center of the
column is printed and no left and right borders are shown.
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.
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 |
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 printprintMode
- the printing mode for this printableheaderFormat
- a MessageFormat
specifying the text to
be used in printing a header, or null for nonefooterFormat
- a MessageFormat
specifying the text to
be used in printing a footer, or null for none
- Throws:
IllegalArgumentException
- if passed an invalid print mode
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 drawnpageFormat
- the size and orientation of the page being drawnpageIndex
- 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