org.tentackle.print
Class Report

java.lang.Object
  extended by org.tentackle.print.Report
All Implemented Interfaces:
Pageable, Printable

public class Report
extends Object
implements Printable, Pageable

A generic report.

Can be used as Printable or Pageable. If used as Pageable the number of pages will be determined in dummy pass first and then printed in a second pass. If used as a Printable there is only one pass.

The report is implemented as a statemachine and gets its data from a ReportSource.

Author:
harald

Field Summary
static int CENTER
          center panel
static int EAST
          align right
static int NORTH
          align top
static int NORTHEAST
          align top right
static int NORTHWEST
          align top left (default)
static int SCALE_FIXED
          fixed scaling (default = 1.0)
static int SCALE_IF_WIDER
          scale (make smaller) to fit if wider than paper
static int SCALE_TO_FIT
          scale to paper-width (enlarge or shrink)
static int SOUTH
          align bottom
static int SOUTHEAST
          align bottom right
static int SOUTHWEST
          align bottom left
static int WEST
          align left
 
Fields inherited from interface java.awt.print.Printable
NO_SUCH_PAGE, PAGE_EXISTS
 
Fields inherited from interface java.awt.print.Pageable
UNKNOWN_NUMBER_OF_PAGES
 
Constructor Summary
Report(ReportSource source, PageFormat pageFormat)
          Creates a standard report which honors the imageable size and has no sublevels.
Report(ReportSource source, PageFormat pageFormat, boolean imageable, int subLevels)
          Creates a report.
 
Method Summary
 int currentPage()
          Get the current page-number.
 int currentState()
          Gets the current state.
 int getAdvance()
          Gets last returned code.
 int getAutoScale()
          Gets the autoscale mode.
 int getLevel()
          Get the current logical group level.
 int getMoveAfter()
          Gets the pending pixels to move after printing the next panel.
 int getMoveBefore()
          Gets the pending pixels to move before printing the next panel.
 int getNumberOfPages()
          Determines the number of pages *before* running the report.
 PageFormat getPageFormat(int pageIndex)
          Returns the PageFormat of the page specified by pageIndex.
 Printable getPrintable(int pageIndex)
          Returns the Printable instance responsible for rendering the page specified by pageIndex.
 Runnable getRunAfter()
          Gets therunnable to be executed once after printing the next panel
 Runnable getRunBefore()
          Gets the runnable to be executed once before printing the next panel.
 double getScale()
          Gets the current scaling
 int getYMax()
          Retrieves the maximum printed y position so far for current page.
 int getYOffset()
          Retrieves the maximum printed y offset so far for current page.
 int print(Graphics graphics, PageFormat pageFormat, int pageIndex)
          Runs the report.
This implements the interface Printable.
 void setAutoScale(int autoScale)
          Sets the automatic scaling.
 void setFooter(PrintPanel footer)
          Sets the footer panel.
 void setFooterAlignment(int align)
          Sets the aligment of the footer.
 void setFooterSize(Dimension size)
          Optionally sets the size of the footer if not derived from the print panel.
 void setHeader(PrintPanel header)
          Sets the header panel.
 void setHeaderAlignment(int align)
          Sets the aligment of the header.
 void setHeaderSize(Dimension size)
          Optionally sets the size of the header if not derived from the print panel.
 void setIntro(PrintPanel intro)
          Sets the intro panel.
 void setIntroAlignment(int align)
          Sets the aligment of the intro.
 void setIntroSize(Dimension size)
          Optionally sets the size of the intro if not derived from the print panel.
 void setLine(PrintPanel line)
          Sets the panel for printing the data line.
 void setLineAlignment(int align)
          Sets the aligment of the data line.
 void setLineSize(Dimension size)
          Optionally sets the size of the data line if not derived from the print panel.
 void setMoveAfter(int moveAfter)
          Sets the pixels to move after printing the next panel.
The attribute will be cleared when used.
 void setMoveBefore(int moveBefore)
          Sets the pixels to move before printing the next panel.
The attribute will be cleared when used.
 void setRunAfter(Runnable runAfter)
          Sets a runnable to be executed once after printing the next panel
 void setRunBefore(Runnable runBefore)
          Sets a runnable to be executed once before printing the next panel.
 void setScale(double scale)
          Sets the scaling.
 void setSubFooter(PrintPanel[] subFooter)
          Sets the subfooters.
 void setSubFooterAlignment(int[] align)
          Sets the aligment of the subfooters.
 void setSubFooterSize(Dimension[] sizes)
          Optionally sets the size of the subfooters if not derived from the print panel.
 void setSubHeader(PrintPanel[] subHeader)
          Sets the subheaders.
 void setSubHeaderAlignment(int[] align)
          Sets the aligment of the subheaders.
 void setSubHeaderSize(Dimension[] sizes)
          Optionally sets the size of the subheaders if not derived from the print panel.
 void setTrailer(PrintPanel trailer)
          Sets the trailer panel.
 void setTrailerAlignment(int align)
          Sets the aligment of the trailer.
 void setTrailerSize(Dimension size)
          Optionally sets the size of the trailer if not derived from the print panel.
 void triggerPrintAgain()
          Triggers the last panel to be printed again.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NORTHWEST

public static final int NORTHWEST
align top left (default)

See Also:
Constant Field Values

NORTHEAST

public static final int NORTHEAST
align top right

See Also:
Constant Field Values

SOUTHWEST

public static final int SOUTHWEST
align bottom left

See Also:
Constant Field Values

SOUTHEAST

public static final int SOUTHEAST
align bottom right

See Also:
Constant Field Values

CENTER

public static final int CENTER
center panel

See Also:
Constant Field Values

EAST

public static final int EAST
align right

See Also:
Constant Field Values

WEST

public static final int WEST
align left

See Also:
Constant Field Values

SOUTH

public static final int SOUTH
align bottom

See Also:
Constant Field Values

NORTH

public static final int NORTH
align top

See Also:
Constant Field Values

SCALE_FIXED

public static final int SCALE_FIXED
fixed scaling (default = 1.0)

See Also:
Constant Field Values

SCALE_IF_WIDER

public static final int SCALE_IF_WIDER
scale (make smaller) to fit if wider than paper

See Also:
Constant Field Values

SCALE_TO_FIT

public static final int SCALE_TO_FIT
scale to paper-width (enlarge or shrink)

See Also:
Constant Field Values
Constructor Detail

Report

public Report(ReportSource source,
              PageFormat pageFormat,
              boolean imageable,
              int subLevels)
Creates a report.

Parameters:
source - the data source for this report
pageFormat - the pageformat
imageable - true if honor the imageable size, else full page size
subLevels - number of sublevels, default is 0 (no groups)

Report

public Report(ReportSource source,
              PageFormat pageFormat)
Creates a standard report which honors the imageable size and has no sublevels.

Parameters:
source - the data source for this report
pageFormat - the pageformat
Method Detail

setIntro

public void setIntro(PrintPanel intro)
              throws PrinterException
Sets the intro panel. The intro will be printed at the beginning of the report.

Parameters:
intro - the intro panel, null for none (i.e. print header instead)
Throws:
PrinterException

setTrailer

public void setTrailer(PrintPanel trailer)
                throws PrinterException
Sets the trailer panel. The trailer will be printed at the end of the report.

Parameters:
trailer - the trailer panel, null for none (i.e. print footer instead)
Throws:
PrinterException

setHeader

public void setHeader(PrintPanel header)
               throws PrinterException
Sets the header panel. The header will be printed at the start of each page, except the first if the intro is set.

Parameters:
header - the header panel, null for none.
Throws:
PrinterException

setFooter

public void setFooter(PrintPanel footer)
               throws PrinterException
Sets the footer panel. The footer will be printed at the end of each page, except the last if the trailer is set.

Parameters:
footer - the footer panel, null for none.
Throws:
PrinterException

setLine

public void setLine(PrintPanel line)
             throws PrinterException
Sets the panel for printing the data line.

Parameters:
line - the line panel, null if none
Throws:
PrinterException

setSubHeader

public void setSubHeader(PrintPanel[] subHeader)
                  throws PrinterException
Sets the subheaders.

Parameters:
subHeader - the array of subheaders (size must match levels)
Throws:
PrinterException

setSubFooter

public void setSubFooter(PrintPanel[] subFooter)
                  throws PrinterException
Sets the subfooters.

Parameters:
subFooter - the array of subfooter (size must match levels)
Throws:
PrinterException

setIntroAlignment

public void setIntroAlignment(int align)
                       throws PrinterException
Sets the aligment of the intro.

Parameters:
align - the alignment
Throws:
PrinterException

setTrailerAlignment

public void setTrailerAlignment(int align)
                         throws PrinterException
Sets the aligment of the trailer.

Parameters:
align - the alignment
Throws:
PrinterException

setHeaderAlignment

public void setHeaderAlignment(int align)
                        throws PrinterException
Sets the aligment of the header.

Parameters:
align - the alignment
Throws:
PrinterException

setFooterAlignment

public void setFooterAlignment(int align)
                        throws PrinterException
Sets the aligment of the footer.

Parameters:
align - the alignment
Throws:
PrinterException

setLineAlignment

public void setLineAlignment(int align)
                      throws PrinterException
Sets the aligment of the data line.

Parameters:
align - the alignment
Throws:
PrinterException

setSubHeaderAlignment

public void setSubHeaderAlignment(int[] align)
                           throws PrinterException
Sets the aligment of the subheaders.

Parameters:
align - the array of alignments (size must match levels)
Throws:
PrinterException

setSubFooterAlignment

public void setSubFooterAlignment(int[] align)
                           throws PrinterException
Sets the aligment of the subfooters.

Parameters:
align - the array of alignments (size must match levels)
Throws:
PrinterException

setIntroSize

public void setIntroSize(Dimension size)
                  throws PrinterException
Optionally sets the size of the intro if not derived from the print panel.

Parameters:
size - the dimension
Throws:
PrinterException

setTrailerSize

public void setTrailerSize(Dimension size)
                    throws PrinterException
Optionally sets the size of the trailer if not derived from the print panel.

Parameters:
size - the dimension
Throws:
PrinterException

setHeaderSize

public void setHeaderSize(Dimension size)
                   throws PrinterException
Optionally sets the size of the header if not derived from the print panel.

Parameters:
size - the dimension
Throws:
PrinterException

setFooterSize

public void setFooterSize(Dimension size)
                   throws PrinterException
Optionally sets the size of the footer if not derived from the print panel.

Parameters:
size - the dimension
Throws:
PrinterException

setLineSize

public void setLineSize(Dimension size)
                 throws PrinterException
Optionally sets the size of the data line if not derived from the print panel.

Parameters:
size - the dimension
Throws:
PrinterException

setSubHeaderSize

public void setSubHeaderSize(Dimension[] sizes)
                      throws PrinterException
Optionally sets the size of the subheaders if not derived from the print panel.

Parameters:
sizes - the array of dimensions (must match levels)
Throws:
PrinterException

setSubFooterSize

public void setSubFooterSize(Dimension[] sizes)
                      throws PrinterException
Optionally sets the size of the subfooters if not derived from the print panel.

Parameters:
sizes - the array of dimensions (must match levels)
Throws:
PrinterException

getLevel

public int getLevel()
Get the current logical group level.

Returns:
the logical level of the statemachine, 0 = top, 1 = first data group, etc...

currentState

public int currentState()
Gets the current state.

Returns:
the state
See Also:
ReportSource.advance(org.tentackle.print.Report)

currentPage

public int currentPage()
Get the current page-number. Pages start at 1.

Returns:
the page number

setScale

public void setScale(double scale)
Sets the scaling. Overwrites the automatic scaling.

Parameters:
scale - the scaling

getScale

public double getScale()
Gets the current scaling

Returns:
the scaling

setAutoScale

public void setAutoScale(int autoScale)
Sets the automatic scaling. (one of SCALE_...)

Parameters:
autoScale - the scale mode

getAutoScale

public int getAutoScale()
Gets the autoscale mode.

Returns:
the scale mode

setMoveBefore

public void setMoveBefore(int moveBefore)
Sets the pixels to move before printing the next panel.
The attribute will be cleared when used.

Parameters:
moveBefore - the number of pixels (> 0 to move down)

getMoveBefore

public int getMoveBefore()
Gets the pending pixels to move before printing the next panel.

Returns:
the pixels to move before printing the next panel

setMoveAfter

public void setMoveAfter(int moveAfter)
Sets the pixels to move after printing the next panel.
The attribute will be cleared when used.

Parameters:
moveAfter - the number of pixels (> 0 to move down)

getMoveAfter

public int getMoveAfter()
Gets the pending pixels to move after printing the next panel.

Returns:
the pixels to move after printing the next panel

setRunBefore

public void setRunBefore(Runnable runBefore)
Sets a runnable to be executed once before printing the next panel.

Parameters:
runBefore - the runnable

getRunBefore

public Runnable getRunBefore()
Gets the runnable to be executed once before printing the next panel.

Returns:
the runnable

setRunAfter

public void setRunAfter(Runnable runAfter)
Sets a runnable to be executed once after printing the next panel

Parameters:
runAfter - the runnable

getRunAfter

public Runnable getRunAfter()
Gets therunnable to be executed once after printing the next panel

Returns:
the runnable

triggerPrintAgain

public void triggerPrintAgain()
Triggers the last panel to be printed again.


getYMax

public int getYMax()
Retrieves the maximum printed y position so far for current page.

Returns:
the max y-position

getYOffset

public int getYOffset()
Retrieves the maximum printed y offset so far for current page.

Returns:
the max y-offset

getAdvance

public int getAdvance()
Gets last returned code.

Returns:
the last advance code
See Also:
ReportSource.advance(org.tentackle.print.Report)

getNumberOfPages

public int getNumberOfPages()
Determines the number of pages *before* running the report. If used as a Pageable this method will be invoked from PrinterJob.

Specified by:
getNumberOfPages in interface Pageable
Returns:
the number of pages in this Pageable.

print

public int print(Graphics graphics,
                 PageFormat pageFormat,
                 int pageIndex)
          throws PrinterException
Runs the report.
This implements the interface Printable.

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 pageIndex specifies a non-existent page.
Throws:
PrinterException - thrown when the print job is terminated.

getPageFormat

public PageFormat getPageFormat(int pageIndex)
                         throws IndexOutOfBoundsException
Description copied from interface: java.awt.print.Pageable
Returns the PageFormat of the page specified by pageIndex.

Specified by:
getPageFormat in interface Pageable
Parameters:
pageIndex - the zero based index of the page whose PageFormat is being requested
Returns:
the PageFormat describing the size and orientation.
Throws:
IndexOutOfBoundsException - if the Pageable does not contain the requested page.

getPrintable

public Printable getPrintable(int pageIndex)
                       throws IndexOutOfBoundsException
Description copied from interface: java.awt.print.Pageable
Returns the Printable instance responsible for rendering the page specified by pageIndex.

Specified by:
getPrintable in interface Pageable
Parameters:
pageIndex - the zero based index of the page whose Printable is being requested
Returns:
the Printable that renders the page.
Throws:
IndexOutOfBoundsException - if the Pageable does not contain the requested page.


Copyright © 2001-2008 Harald Krake, Bergstr. 48, 78098 Triberg, Germany, harald@krake.de