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

java.lang.Object
  |
  +--com.jrefinery.report.targets.pageable.output.PrinterCommandSet
Direct Known Subclasses:
EpsonPrinterCommandSet, IBMPrinterCommandSet

public class PrinterCommandSet
extends java.lang.Object

Implements a printer command set for plain text output. The output is not enriched with any printer specific control sequences.

Author:
Thomas Morgner

Field Summary
static byte CARRIAGE_RETURN
          the Carriage Return control character, the printer carriage returns to the start of the line.
static byte FORM_FEED
          the form feed character, ejects the current page and starts the next page.
static byte LINE_FEED
          scrolls the paper up a single line.
static byte SELECT_FONT_COURIER
          the courier font.
static byte SELECT_FONT_FROM_MENU
          selects the font, which is selected on the printer menu.
static byte SELECT_FONT_GOTHIC
          the gothic font.
static byte SELECT_FONT_OCR_A
          the OCR-A font.
static byte SELECT_FONT_OCR_B
          the OCR-B font.
static byte SELECT_FONT_ORATOR
          the orator font.
static byte SELECT_FONT_PRESTIGE
          the prestige font.
static byte SELECT_FONT_ROMAN
          the roman font.
static byte SELECT_FONT_SWISS
          the swiss font.
static byte SELECT_FONT_SWISS_BOLD
          the swiss-bold font.
static byte SPACE
          the space character.
 
Constructor Summary
PrinterCommandSet(java.io.OutputStream out, java.awt.print.PageFormat format, int defaultCPI, int defaultLPI)
          Creates a new PrinterCommandSet.
 
Method Summary
 void endLine()
          Ends a new line.
 void endPage()
          Ends the current page.
 void flush()
          Flushes the output stream.
 int getBorderBottom()
          Returns the bottom border in lines.
 int getBorderLeft()
          Returns the left border in characters.
 int getBorderRight()
          Returns the right border in characters.
 int getBorderTop()
          Returns the top border in lines.
 byte getCharacterWidth()
          Gets the character width in CPI.
 java.lang.String getCodepage()
          Returns the current codepage of the printer.
 int getDefaultCPI()
          Gets the default character width in CPI.
 int getDefaultLPI()
          Gets the default character height in CPI.
 byte getFont()
          Returns the defined font selection byte.
 int getLineSpacing()
          Returns the line spacing for the printer, the spacing is given in 1/1440 inches.
protected  java.io.OutputStream getOut()
          Gets the outputstream that is used to write the generated content.
 java.awt.print.PageFormat getPageFormat()
          Gets the pageformat used in this command set.
 int getPaperSize()
          Returns the paper size in lines.
 boolean isAutoLf()
          Gets the AutoLF flag.
 boolean isBold()
          Gets the bold format flag.
 boolean isEncodingSupported(java.lang.String encoding)
          Tests whether the given encoding is supported.
 boolean isItalic()
          Gets the italic format flag.
 boolean isLetterQuality()
          Gets the letter quality flag.
 boolean isStrikethrough()
          Gets the strikethrough format flag.
 boolean isUnderline()
          Gets the underline format flag.
 void printChunk(PlainTextPage.TextDataChunk chunk, int x)
          Prints a single text chunk.
 void printEmptyChunk()
          Prints an empty chunk.
 void resetPrinter()
          Resets the printer to the default values.
 void setAutoLF(boolean autoLF)
          Defines whether to print in AutoLF mode.
 void setCharacterWidth(byte charWidth)
          Defines the character width for the current font.
 void setCodePage(java.lang.String codepage)
          Defines the code page for the text to be printed.
 void setFont(byte fontSelection)
          Defines the font.
 void setFontStyle(boolean bold, boolean italic, boolean underline, boolean strike)
          Defines the font style for the printed text.
 void setHorizontalBorder(int left, int right)
          Defines the horizontal borders for the current paper.
 void setLineSpacing(int spaceInInch)
          Defines the line spacing for the printer, the spacing is given in 1/1440 inches.
 void setPaperSize(int lines)
          Defines the papersize in lines.
 void setPrintQuality(boolean letterQuality)
          Defines the printing quality for the printed text.
 void setVerticalBorder(int top, int bottom)
          Defines the horizontal borders for the current paper.
 void startLine()
          Starts a new line.
 void startPage()
          Starts the current page.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SELECT_FONT_ROMAN

public static final byte SELECT_FONT_ROMAN
the roman font.

See Also:
Constant Field Values

SELECT_FONT_SWISS

public static final byte SELECT_FONT_SWISS
the swiss font.

See Also:
Constant Field Values

SELECT_FONT_COURIER

public static final byte SELECT_FONT_COURIER
the courier font.

See Also:
Constant Field Values

SELECT_FONT_PRESTIGE

public static final byte SELECT_FONT_PRESTIGE
the prestige font.

See Also:
Constant Field Values

SELECT_FONT_OCR_A

public static final byte SELECT_FONT_OCR_A
the OCR-A font.

See Also:
Constant Field Values

SELECT_FONT_OCR_B

public static final byte SELECT_FONT_OCR_B
the OCR-B font.

See Also:
Constant Field Values

SELECT_FONT_ORATOR

public static final byte SELECT_FONT_ORATOR
the orator font.

See Also:
Constant Field Values

SELECT_FONT_SWISS_BOLD

public static final byte SELECT_FONT_SWISS_BOLD
the swiss-bold font.

See Also:
Constant Field Values

SELECT_FONT_GOTHIC

public static final byte SELECT_FONT_GOTHIC
the gothic font.

See Also:
Constant Field Values

SELECT_FONT_FROM_MENU

public static final byte SELECT_FONT_FROM_MENU
selects the font, which is selected on the printer menu.

See Also:
Constant Field Values

CARRIAGE_RETURN

public static final byte CARRIAGE_RETURN
the Carriage Return control character, the printer carriage returns to the start of the line.

See Also:
Constant Field Values

LINE_FEED

public static final byte LINE_FEED
scrolls the paper up a single line.

See Also:
Constant Field Values

FORM_FEED

public static final byte FORM_FEED
the form feed character, ejects the current page and starts the next page.

See Also:
Constant Field Values

SPACE

public static final byte SPACE
the space character.

See Also:
Constant Field Values
Constructor Detail

PrinterCommandSet

public PrinterCommandSet(java.io.OutputStream out,
                         java.awt.print.PageFormat format,
                         int defaultCPI,
                         int defaultLPI)
Creates a new PrinterCommandSet.

Parameters:
out - the target output stream
format - the pageformat of the used report
defaultCPI - the characters-per-inch for the output.
defaultLPI - the lines-per-inch for the output.
Method Detail

getPageFormat

public java.awt.print.PageFormat getPageFormat()
Gets the pageformat used in this command set.

Returns:
the pageformat.

getDefaultCPI

public int getDefaultCPI()
Gets the default character width in CPI.

Returns:
the default character width in CPI.

getDefaultLPI

public int getDefaultLPI()
Gets the default character height in CPI.

Returns:
the default character height in CPI.

getOut

protected java.io.OutputStream getOut()
Gets the outputstream that is used to write the generated content.

Returns:
the output stream.

setFont

public void setFont(byte fontSelection)
             throws java.io.IOException
Defines the font. Does nothing.

Parameters:
fontSelection - the font selection byte.
Throws:
java.io.IOException - is not thrown here.

getFont

public byte getFont()
Returns the defined font selection byte.

Returns:
the font selection byte.

setCharacterWidth

public void setCharacterWidth(byte charWidth)
                       throws java.io.IOException
Defines the character width for the current font. The width is specified in Characters-per-inch. Valid values are 10, 12, 15, 17 and 20 cpi.

Parameters:
charWidth - the character width in CPI.
Throws:
java.io.IOException - if there was an IOError while writing the command or if the character width is not supported by the printer.

getCharacterWidth

public byte getCharacterWidth()
Gets the character width in CPI.

Returns:
the character width.

setFontStyle

public void setFontStyle(boolean bold,
                         boolean italic,
                         boolean underline,
                         boolean strike)
                  throws java.io.IOException
Defines the font style for the printed text. The IBM-CommandSet does not support strike-through.

Parameters:
bold - true, if the text should be printed in bold mode.
italic - true, if the text should be italic, false otherwise
underline - true, if the text should be underlined, false otherwise
strike - true, if the text should be strikethrough, false otherwise
Throws:
java.io.IOException - if there was an IOError while writing the command

isStrikethrough

public boolean isStrikethrough()
Gets the strikethrough format flag.

Returns:
the strikethrough font format flag.

isUnderline

public boolean isUnderline()
Gets the underline format flag.

Returns:
the underline font format flag.

isItalic

public boolean isItalic()
Gets the italic format flag.

Returns:
the italic font format flag.

isBold

public boolean isBold()
Gets the bold format flag.

Returns:
the bold font format flag.

setPaperSize

public void setPaperSize(int lines)
                  throws java.io.IOException
Defines the papersize in lines.

Parameters:
lines - the number of lines that could be printed on a single page.
Throws:
java.io.IOException - if there was an IOError while writing the command

getPaperSize

public int getPaperSize()
Returns the paper size in lines.

Returns:
the page height in lines.

setHorizontalBorder

public void setHorizontalBorder(int left,
                                int right)
                         throws java.io.IOException
Defines the horizontal borders for the current paper. The borders are given in characters.

Parameters:
left - the number of spaces printed on the start of a line.
right - the number of spaces left free on the right paper border.
Throws:
java.io.IOException - if an IOException occured while updating the printer state.

setVerticalBorder

public void setVerticalBorder(int top,
                              int bottom)
                       throws java.io.IOException
Defines the horizontal borders for the current paper. The borders are given in characters.

Parameters:
top - the number of blank lines printed on the start of a page.
bottom - the number of blank lines printed at the end of a page
Throws:
java.io.IOException - if an IOException occured while updating the printer state.

getBorderBottom

public int getBorderBottom()
Returns the bottom border in lines.

Returns:
the bottom border.

getBorderTop

public int getBorderTop()
Returns the top border in lines.

Returns:
the top border.

getBorderRight

public int getBorderRight()
Returns the right border in characters.

Returns:
the right border.

getBorderLeft

public int getBorderLeft()
Returns the left border in characters.

Returns:
the left border.

setLineSpacing

public void setLineSpacing(int spaceInInch)
                    throws java.io.IOException
Defines the line spacing for the printer, the spacing is given in 1/1440 inches.

Parameters:
spaceInInch - the linespacing in 1/1440 inches.
Throws:
java.io.IOException - if an IOException occured while updating the printer state.

getLineSpacing

public int getLineSpacing()
Returns the line spacing for the printer, the spacing is given in 1/1440 inches.

Returns:
the linespacing in 1/1440 inches.

setCodePage

public void setCodePage(java.lang.String codepage)
                 throws java.io.IOException
Defines the code page for the text to be printed. The codepage is an 8-Bit encoding scheme to print non-ascii-characters.

Parameters:
codepage - the new codepage that should be used.
Throws:
java.io.IOException - if there was an IOError while writing the command

getCodepage

public java.lang.String getCodepage()
Returns the current codepage of the printer.

Returns:
the code page.

setAutoLF

public void setAutoLF(boolean autoLF)
               throws java.io.IOException
Defines whether to print in AutoLF mode. If AutoLF is enabled, then a linefeed character is automaticly printed after every <CR> character.

Parameters:
autoLF - the new autoLF state
Throws:
java.io.IOException - if there was an IOError while writing the command

setPrintQuality

public void setPrintQuality(boolean letterQuality)
                     throws java.io.IOException
Defines the printing quality for the printed text. Set to true, to enable LetterQuality printing, false enables Draft-Quality.

Parameters:
letterQuality - true, if letter quality should be used, false for draft-quality
Throws:
java.io.IOException - if there was an IOError while writing the command

isLetterQuality

public boolean isLetterQuality()
Gets the letter quality flag.

Returns:
true, if letter quality is enabled.

isAutoLf

public boolean isAutoLf()
Gets the AutoLF flag.

Returns:
true, if AutoLF is enabled.

resetPrinter

public void resetPrinter()
                  throws java.io.IOException
Resets the printer to the default values. This performs a reset and then sets the values defined for this CommandSet.

Throws:
java.io.IOException - if there was an IOError while writing the command

startPage

public void startPage()
               throws java.io.IOException
Starts the current page. Prints empty lines.

Throws:
java.io.IOException - if there was an IOError while writing the command

endPage

public void endPage()
             throws java.io.IOException
Ends the current page. Prints empty lines.

Throws:
java.io.IOException - if there was an IOError while writing the command

startLine

public void startLine()
               throws java.io.IOException
Starts a new line.

Throws:
java.io.IOException - if an IOError occures.

endLine

public void endLine()
             throws java.io.IOException
Ends a new line.

Throws:
java.io.IOException - if an IOError occures.

printChunk

public void printChunk(PlainTextPage.TextDataChunk chunk,
                       int x)
                throws java.io.IOException
Prints a single text chunk. The chunk is not printed, if an previous chunk overlays this chunk,

Parameters:
chunk - the chunk that should be written
x - the column where to start to print the chunk
Throws:
java.io.IOException - if an IO error occured.

printEmptyChunk

public void printEmptyChunk()
                     throws java.io.IOException
Prints an empty chunk. This is called for all undefined chunk-cells.

Throws:
java.io.IOException - if an IOError occured.

flush

public void flush()
           throws java.io.IOException
Flushes the output stream.

Throws:
java.io.IOException - if an IOError occured.

isEncodingSupported

public boolean isEncodingSupported(java.lang.String encoding)
Tests whether the given encoding is supported.

Parameters:
encoding - the encoding that should be tested.
Returns:
true, if the encoding is supported, false otherwise.