com.jrefinery.report.targets.pageable.output
Class G2OutputTarget

java.lang.Object
  |
  +--com.jrefinery.report.targets.pageable.output.AbstractOutputTarget
        |
        +--com.jrefinery.report.targets.pageable.output.G2OutputTarget
All Implemented Interfaces:
LayoutSupport, OutputTarget

public class G2OutputTarget
extends AbstractOutputTarget

A report output target that uses a Graphics2D object to draw the report. This allows reports to be printed on the screen and on the printer.

Author:
David Gilbert, Thomas Morgner

Field Summary
 
Fields inherited from interface com.jrefinery.report.targets.pageable.OutputTarget
AUTHOR, TITLE
 
Constructor Summary
G2OutputTarget(java.awt.Graphics2D g2, java.awt.print.PageFormat pageFormat)
          Constructs an output target for drawing to a Java Graphics2D object.
G2OutputTarget(java.awt.Graphics2D g2, java.awt.print.PageFormat physPageFormat, java.awt.print.PageFormat logPageFormat)
          Constructs an output target for drawing to a Java Graphics2D object.
G2OutputTarget(LogicalPage page, java.awt.Graphics2D graphics)
          Creates a new output target.
 
Method Summary
 void beginPage(PhysicalPage page)
          A page is starting.
 void close()
          Closes the target.
 void configure(ReportConfiguration config)
          Configures the output target.
 OutputTarget createDummyWriter()
          Creates an output target that mimics a real output target, but produces no output.
static java.awt.Graphics2D createEmptyGraphics()
          Creates an empty graphics by using a 1x1 pixel buffered image.
 SizeCalculator createTextSizeCalculator(FontDefinition font)
          Creates a size calculator for the current state of the output target.
 void drawDrawable(DrawableContainer drawable)
          Draws a drawable relative to the current position.
 void drawImage(ImageReference image)
          Draws the image contained in the given ImageReference.
 void drawShape(java.awt.Shape shape)
          Draws a shape.
 void drawString(java.lang.String text)
          Draws a string inside a rectangular area (the lower edge is aligned with the baseline of the text).
 void endPage()
          A page has ended.
 void fillShape(java.awt.Shape shape)
          Fills a shape.
 FontDefinition getFont()
          Returns the current font.
 java.awt.Paint getPaint()
          Returns the current paint.
 java.awt.Stroke getStroke()
          Returns the Stroke for the Graphics2D context.
 boolean isOpen()
          Returns true if the output target is open, and false otherwise.
 void open()
          Opens the target.
 void setFont(FontDefinition font)
          Sets the font.
 void setOperationBounds(java.awt.geom.Rectangle2D bounds)
          Sets the operation bounds.
 void setPaint(java.awt.Paint paint)
          Sets the paint.
 void setStroke(java.awt.Stroke stroke)
          Sets the Stroke for the Graphics2D context.
 
Methods inherited from class com.jrefinery.report.targets.pageable.output.AbstractOutputTarget
createContentFactory, getContentFactory, getHorizontalAlignmentBorder, getLogicalPage, getOperationBounds, getProperty, getProperty, getPropertyNames, getVerticalAlignmentBorder, setProperty
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

G2OutputTarget

public G2OutputTarget(LogicalPage page,
                      java.awt.Graphics2D graphics)
Creates a new output target.

Parameters:
page - the logical page.
graphics - the graphics device.

G2OutputTarget

public G2OutputTarget(java.awt.Graphics2D g2,
                      java.awt.print.PageFormat physPageFormat,
                      java.awt.print.PageFormat logPageFormat)
Constructs an output target for drawing to a Java Graphics2D object.

Parameters:
g2 - the graphics device.
physPageFormat - the page format for the physical page used to print the report.
logPageFormat - the page format for the logical page used to layout the report.

G2OutputTarget

public G2OutputTarget(java.awt.Graphics2D g2,
                      java.awt.print.PageFormat pageFormat)
Constructs an output target for drawing to a Java Graphics2D object.

Parameters:
g2 - the graphics device.
pageFormat - the page format.
Method Detail

createEmptyGraphics

public static java.awt.Graphics2D createEmptyGraphics()
Creates an empty graphics by using a 1x1 pixel buffered image.

Returns:
a Graphics2D instance.

open

public void open()
          throws OutputTargetException
Opens the target.

Throws:
OutputTargetException - if there is a problem with the output target.

close

public void close()
Closes the target.


isOpen

public boolean isOpen()
Returns true if the output target is open, and false otherwise.

Returns:
the open state of this target.

beginPage

public void beginPage(PhysicalPage page)
A page is starting. This target saves the current state of the Graphics2D device.

Parameters:
page - the physical page.

endPage

public void endPage()
             throws OutputTargetException
A page has ended. This target restores the state of the Graphics2D device.

Throws:
OutputTargetException - if there is a problem with the target.

setFont

public void setFont(FontDefinition font)
Sets the font.

Parameters:
font - the font.

getFont

public FontDefinition getFont()
Returns the current font.

Returns:
the font.

setPaint

public void setPaint(java.awt.Paint paint)
Sets the paint.

Parameters:
paint - The paint.

getPaint

public java.awt.Paint getPaint()
Returns the current paint.

Returns:
the paint.

getStroke

public java.awt.Stroke getStroke()
Returns the Stroke for the Graphics2D context.

Returns:
the stroke.

setStroke

public void setStroke(java.awt.Stroke stroke)
               throws OutputTargetException
Sets the Stroke for the Graphics2D context.

Parameters:
stroke - the stroke.
Throws:
OutputTargetException - this exception is not thrown here.

drawShape

public void drawShape(java.awt.Shape shape)
Draws a shape. The shape is drawn using Graphics2D.draw. A paint and a stroke have to be set separately.

Parameters:
shape - The shape.

fillShape

public void fillShape(java.awt.Shape shape)
Fills a shape. The shape is drawn using Graphics2D.draw. A paint and a stroke have to be set separately.

Parameters:
shape - The shape.

drawImage

public void drawImage(ImageReference image)
Draws the image contained in the given ImageReference.

Parameters:
image - the image reference used to contain the image.

drawString

public void drawString(java.lang.String text)
Draws a string inside a rectangular area (the lower edge is aligned with the baseline of the text).

Parameters:
text - The text.

createDummyWriter

public OutputTarget createDummyWriter()
Creates an output target that mimics a real output target, but produces no output. This is used by the reporting engine when it makes its first pass through the report, calculating page boundaries etc. The second pass will use a real output target.

Returns:
a dummy output target.

configure

public void configure(ReportConfiguration config)
Configures the output target.

There are no configuration parameters that affect this output target, so this method does nothing.

Parameters:
config - the configuration.

createTextSizeCalculator

public SizeCalculator createTextSizeCalculator(FontDefinition font)
Creates a size calculator for the current state of the output target. The calculator is used to calculate the string width and line height and later maybe more.

Parameters:
font - the font.
Returns:
the size calculator.

setOperationBounds

public void setOperationBounds(java.awt.geom.Rectangle2D bounds)
Sets the operation bounds.

Specified by:
setOperationBounds in interface OutputTarget
Overrides:
setOperationBounds in class AbstractOutputTarget
Parameters:
bounds - the bounds.

drawDrawable

public void drawDrawable(DrawableContainer drawable)
Draws a drawable relative to the current position.

Parameters:
drawable - the drawable to draw.