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

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

public class PlainTextOutputTarget
extends AbstractOutputTarget

An outputtarget, that generates plaintext. The text can be enriched with escape sequences for Epson- or IBM-Compatible printers.

This target does not support images, shapes or different fonts. The output generation is needle-printer oriented, the pageformat is translated into a text page, graphics coordinates are aligned along the character grid of the text mode.

It is assumed that all characters have the same width, proportional printing is not supported.

The output mode is defined by supplying a suitable PrinterCommandSet. Depending on the target printer, you can supply several PrinterCommandSets:

Author:
Thomas Morgner
See Also:
PrinterCommandSet, IBMPrinterCommandSet, EpsonPrinterCommandSet, PlainTextPage

Field Summary
 
Fields inherited from interface com.jrefinery.report.targets.pageable.OutputTarget
AUTHOR, TITLE
 
Constructor Summary
PlainTextOutputTarget(LogicalPage logicalPage, PrinterCommandSet commandSet)
          Creates a new PlainTextOutputTarget which uses the given command set to write the generated content.
PlainTextOutputTarget(java.awt.print.PageFormat logical, java.awt.print.PageFormat physical, PrinterCommandSet commandSet)
          Creates a new PlainTextOutputTarget which uses the given command set to write the generated content.
PlainTextOutputTarget(java.awt.print.PageFormat format, PrinterCommandSet commandSet)
          Creates a new PlainTextOutputTarget which uses the given command set to write the generated content.
 
Method Summary
 void beginPage(PhysicalPage page)
          Signals that a page is being started.
 void close()
          Closes the target.
 void configure(ReportConfiguration config)
          Does nothing, the OutputTarget is configured by supplying a valid PrinterCommand set.
protected  ContentFactory createContentFactory()
          Creates a content factory.
 OutputTarget createDummyWriter()
          Creates an output target that mimics a real output target, but produces no output.
 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)
          This method is empty, as the PlainTextOutputTarget does not support images.
 void drawShape(java.awt.Shape shape)
          This method is empty, as the PlainTextOutputTarget does not support shapes.
 void drawString(java.lang.String text)
          Draws a string at the current cursor position.
 void endPage()
          Signals that the current page is ended.
 void fillShape(java.awt.Shape shape)
          This method is empty, as the PlainTextOutputTarget does not support shapes.
 PrinterCommandSet getCommandSet()
          Gets the printercommandset used to format the text.
 FontDefinition getFont()
          Returns the current font.
 float getHorizontalAlignmentBorder()
          Returns the element alignment.
 java.awt.Paint getPaint()
          Returns the current paint.
 java.awt.Stroke getStroke()
          Returns the current stroke.
 float getVerticalAlignmentBorder()
          Returns the element alignment.
 boolean isOpen()
          Returns true if the target is open, and false otherwise.
 void open()
          Opens the target.
 void restoreState()
          Restores the state of this graphics.
 void setFont(FontDefinition font)
          Sets the font.
 void setPaint(java.awt.Paint paint)
          Sets the paint.
 void setStroke(java.awt.Stroke stroke)
          Defines the current stroke for the target.
 
Methods inherited from class com.jrefinery.report.targets.pageable.output.AbstractOutputTarget
getContentFactory, getLogicalPage, getOperationBounds, getProperty, getProperty, getPropertyNames, setOperationBounds, setProperty
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PlainTextOutputTarget

public PlainTextOutputTarget(java.awt.print.PageFormat format,
                             PrinterCommandSet commandSet)
Creates a new PlainTextOutputTarget which uses the given command set to write the generated content.

Parameters:
format - the page format.
commandSet - the printer commandset used to write the generated content.
Throws:
java.lang.NullPointerException - if the printer command set is null

PlainTextOutputTarget

public PlainTextOutputTarget(java.awt.print.PageFormat logical,
                             java.awt.print.PageFormat physical,
                             PrinterCommandSet commandSet)
Creates a new PlainTextOutputTarget which uses the given command set to write the generated content.

Parameters:
commandSet - the printer commandset used to write the generated content.
logical - the page format used by this target for layouting.
physical - the page format used by this target for printing.
Throws:
java.lang.NullPointerException - if the printer command set is null

PlainTextOutputTarget

public PlainTextOutputTarget(LogicalPage logicalPage,
                             PrinterCommandSet commandSet)
Creates a new PlainTextOutputTarget which uses the given command set to write the generated content.

Parameters:
commandSet - the printer commandset used to write the generated content.
logicalPage - the page format used by this target for layouting.
Throws:
java.lang.NullPointerException - if the printer command set is null
Method Detail

getCommandSet

public PrinterCommandSet getCommandSet()
Gets the printercommandset used to format the text.

Returns:
the printer command set.

open

public void open()
          throws OutputTargetException
Opens the target.

Throws:
OutputTargetException - if there is some problem opening the target.

isOpen

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

Returns:
true or false.

close

public void close()
Closes the target.


beginPage

public void beginPage(PhysicalPage page)
Signals that a page is being started. Stores the state of the target to make it possible to restore the complete output target.

Parameters:
page - the physical page.

endPage

public void endPage()
             throws OutputTargetException
Signals that the current page is ended. Writes the page buffer to the printer.

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

restoreState

public void restoreState()
                  throws OutputTargetException
Restores the state of this graphics.

Throws:
OutputTargetException - if the argument is not an instance of G2State.

getFont

public FontDefinition getFont()
Returns the current font.

Returns:
the current font.

setFont

public void setFont(FontDefinition font)
             throws OutputTargetException
Sets the font. This has no influence on the generated output.

Parameters:
font - the font.
Throws:
OutputTargetException - if there is a problem setting the font.

getStroke

public java.awt.Stroke getStroke()
Returns the current stroke.

Returns:
the stroke.

setStroke

public void setStroke(java.awt.Stroke stroke)
               throws OutputTargetException
Defines the current stroke for the target. This has no influence on the generated output.

Parameters:
stroke - the stroke.
Throws:
OutputTargetException - if there is a problem setting the stroke.

getPaint

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

Returns:
the paint.

setPaint

public void setPaint(java.awt.Paint paint)
              throws OutputTargetException
Sets the paint. This has no influence on the generated output.

Parameters:
paint - The paint.
Throws:
OutputTargetException - if there is a problem setting the paint.

drawString

public void drawString(java.lang.String text)
Draws a string at the current cursor position.

Parameters:
text - the text.

drawShape

public void drawShape(java.awt.Shape shape)
This method is empty, as the PlainTextOutputTarget does not support shapes.

Parameters:
shape - the shape to draw.

fillShape

public void fillShape(java.awt.Shape shape)
This method is empty, as the PlainTextOutputTarget does not support shapes.

Parameters:
shape - the shape to draw.

drawImage

public void drawImage(ImageReference image)
               throws OutputTargetException
This method is empty, as the PlainTextOutputTarget does not support images.

Parameters:
image - The image to draw (as ImageReference for possible embedding of raw data).
Throws:
OutputTargetException - if there is a problem setting the paint.

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)
Does nothing, the OutputTarget is configured by supplying a valid PrinterCommand set.

Parameters:
config - the configuration.

createTextSizeCalculator

public SizeCalculator createTextSizeCalculator(FontDefinition font)
                                        throws OutputTargetException
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.
Throws:
OutputTargetException - if there is a problem with the output target.

getHorizontalAlignmentBorder

public float getHorizontalAlignmentBorder()
Returns the element alignment. Elements will be layouted aligned to this border, so that mod(X, horizontalAlignment) == 0 and mod(Y, verticalAlignment) == 0

Specified by:
getHorizontalAlignmentBorder in interface LayoutSupport
Overrides:
getHorizontalAlignmentBorder in class AbstractOutputTarget
Returns:
the vertical alignment grid boundry

getVerticalAlignmentBorder

public float getVerticalAlignmentBorder()
Returns the element alignment. Elements will be layouted aligned to this border, so that mod(X, horizontalAlignment) == 0 and mod(Y, verticalAlignment) == 0

Specified by:
getVerticalAlignmentBorder in interface LayoutSupport
Overrides:
getVerticalAlignmentBorder in class AbstractOutputTarget
Returns:
the vertical alignment grid boundry

createContentFactory

protected ContentFactory createContentFactory()
Creates a content factory. The factory does only support TextContent.

Overrides:
createContentFactory in class AbstractOutputTarget
Returns:
the created content factory.

drawDrawable

public void drawDrawable(DrawableContainer drawable)
Draws a drawable relative to the current position. Drawables are not supported, they do not provide text information...

Parameters:
drawable - the drawable to draw.