CoffeeTable.Grid
Class GridPrinterBase

java.lang.Object
  |
  +--CoffeeTable.Grid.GridPrinterBase
Direct Known Subclasses:
GridPrintable, GridPrinter

public class GridPrinterBase
extends java.lang.Object

GridPrinterBase is a helper class that provides Report printing capabilities for the GridPanel. This class figures out the required number of pages to fit all the Grid data and prints it in a report format. The default implementation uses the Grid's drawing methods to print the report.

This class is sub-classed by the GridPrinter class (for JDK 1.1 style printing) and the GridPrintable class (for JDK 1.2 style printing). You don't use this class directly but rather it's sub-classes GridPrinter or GridPrintable depending on your Java VM.

Version:
2.1.3 of October 1, 1999 Copyright © 1996-1999 3Magic

Field Summary
static int CENTER
          Align the printed area at the center of each page.
static int CENTER_LEFT
          Align the printed area at the vertical center of each page.
protected  boolean fAutoResizeColumns
           
protected  java.lang.Boolean fAutoResizeRows
           
protected  java.util.Vector fColRatios
           
protected  java.awt.Point fEndCell
           
protected  int fEndPage
           
protected  int fFooterHeight
           
protected  GridPanelInterface fGrid
           
protected  CoffeeTable.Grid.RunVector fGridHeights
           
protected  java.util.Vector fGridWidths
           
protected  int fHeaderHeight
           
protected  java.awt.Rectangle fPageArea
           
protected  java.awt.Dimension fPages
           
protected  java.awt.Dimension fPageSize
           
protected  int fPrintAlignment
           
protected  java.awt.Rectangle fPrintArea
           
protected  boolean fPrintBorder
           
protected  java.lang.Boolean fPrintColHeaders
           
protected  java.lang.Boolean fPrintColLines
           
protected  java.lang.Boolean fPrintRowHeaders
           
protected  java.lang.Boolean fPrintRowLines
           
protected  int fScreenRes
           
protected  java.awt.Point fStartCell
           
protected  int fStartPage
           
protected  java.lang.String fTitle
           
static int TOP_CENTER
          Align the printed area at the horizontal center of each page.
static int TOP_LEFT
          Align the printed area at the top-left corner of each page.
 
Constructor Summary
GridPrinterBase(java.lang.String title)
          Constructs a new empty GridPrinterBase Object.
GridPrinterBase(java.lang.String title, GridPanelInterface grid)
          Constructs a new empty GridPrinterBase Object for the specified Grid.
 
Method Summary
protected  int calcColRange(int fromCol)
           
protected  void calcColWidths()
           
protected  void calcPageAreas()
           
protected  void calcPages()
           
protected  int calcRowHeight(int row)
           
protected  void calcRowHeights()
           
protected  int calcRowRange(int fromRow)
           
 void drawCell(java.awt.Graphics pg, java.awt.Point cell, java.awt.Rectangle cellRect)
          Print the cell.
 void drawHeaderCol(java.awt.Graphics pg, int col, java.awt.Rectangle aRect)
          Print the header for a column.
 void drawHeaderRow(java.awt.Graphics pg, int row, java.awt.Rectangle aRect)
          Print the header for a row.
 void drawIntersection(java.awt.Graphics pg, java.awt.Rectangle aRect)
          Print the area in the intersection between the row and column headers.
 int getColWidth(int col)
          Return the width for a column.
protected  int getColWidths(int startCol, int numCols)
           
 GridPanelInterface getGrid()
          Returns the Grid associated with this GridPrinter object.
 int getNumPages()
          Return the total number of pages to be printed.
 java.awt.Rectangle getPageArea()
          Returns the printable area for the grid on a page after calculating it based on the printable area of the page, taking the page header and footer dimensions into consideration.
 int getPageFooterHeight()
          Returns the page footer height
 int getPageHeaderHeight()
          Returns the page header height
 java.awt.Rectangle getPrintableArea()
          Returns the printable area of a page.
 int getPrintAlignment()
          Returns the current print alignment.
 boolean getPrintBorder()
          Check if printing a border around a page boundary is enabled.
 boolean getPrintColHeaders()
          Check if printing column headers is enabled.
 boolean getPrintColLines()
          Check if printing column lines is specified.
 boolean getPrintRowHeaders()
          Check if printing row headers is enabled.
 boolean getPrintRowLines()
          Check if printing row lines is specified.
 int getRowHeight(int row)
          Return the height for a row.
protected  int getRowHeights(int startRow, int numRows)
           
 java.lang.String getTitle()
          Return the title for this report.
 boolean isAutoResizeColumns()
          Check if automatically resizing columns to fit in a page is enabled.
 boolean isAutoResizeRows()
          Check if the feature to automatically resize rows is enabled.
 void printFooter(java.awt.Graphics pg, int page, java.awt.Rectangle footerRect)
          Prints the page footer.
 void printHeader(java.awt.Graphics pg, int page, java.awt.Rectangle headerRect)
          Prints the page header.
 void printPage(java.awt.Graphics pg, int page, int fromRow, int toRow, int fromCol, int toCol, java.awt.Rectangle pageRect)
          Prints the Grid data.
 void setAutoResizeColumns(boolean autoResizeColumns)
          Set the flag to automatically resize all columns proportionally to fit on a page.
 void setAutoResizeRows(boolean autoResizeRows)
          Set the flag to automatically resize row heights based on the cell text and column width if WORD_WRAP is enabled for any of the cells.
 void setColWidths(int[] colWidths)
          Set the column widths for this report.
 void setGrid(GridPanelInterface grid)
          Set the Grid to be printed.
 void setPageFooterHeight(int footerHeight)
          Set the height for the page footer.
 void setPageHeaderHeight(int headerHeight)
          Set the height for the page header.
 void setPageRange(int startPage, int endPage)
          Set the range of pages to be printed.
 void setPrintableArea(java.awt.Rectangle printableArea)
          Set the printable area of the page.
 void setPrintAlignment(int printAlignment)
          Set the print alignment.
 void setPrintBorder(boolean printBorder)
          Set the flag to enable or disable the printing of a border around the page boundary.
 void setPrintColHeaders(boolean printColHeaders)
          Set the flag to enable or disable the printing of column headers.
 void setPrintColLines(boolean printColLines)
          Set the flag to enable or disable the printing of column lines.
 void setPrintRowHeaders(boolean printRowHeaders)
          Set the flag to enable or disable the printing of row headers.
 void setPrintRowLines(boolean printRowLines)
          Set the flag to enable or disable the printing of row lines.
 void setTitle(java.lang.String title)
          Set the title for this report.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TOP_LEFT

public static int TOP_LEFT
Align the printed area at the top-left corner of each page.

CENTER

public static int CENTER
Align the printed area at the center of each page.

TOP_CENTER

public static int TOP_CENTER
Align the printed area at the horizontal center of each page.

CENTER_LEFT

public static int CENTER_LEFT
Align the printed area at the vertical center of each page.

fPageSize

protected java.awt.Dimension fPageSize

fScreenRes

protected int fScreenRes

fGrid

protected GridPanelInterface fGrid

fPrintArea

protected java.awt.Rectangle fPrintArea

fPageArea

protected java.awt.Rectangle fPageArea

fStartPage

protected int fStartPage

fEndPage

protected int fEndPage

fPages

protected java.awt.Dimension fPages

fPrintBorder

protected boolean fPrintBorder

fPrintColHeaders

protected java.lang.Boolean fPrintColHeaders

fPrintRowHeaders

protected java.lang.Boolean fPrintRowHeaders

fPrintRowLines

protected java.lang.Boolean fPrintRowLines

fPrintColLines

protected java.lang.Boolean fPrintColLines

fHeaderHeight

protected int fHeaderHeight

fFooterHeight

protected int fFooterHeight

fTitle

protected java.lang.String fTitle

fStartCell

protected java.awt.Point fStartCell

fEndCell

protected java.awt.Point fEndCell

fPrintAlignment

protected int fPrintAlignment

fAutoResizeColumns

protected boolean fAutoResizeColumns

fAutoResizeRows

protected java.lang.Boolean fAutoResizeRows

fGridWidths

protected java.util.Vector fGridWidths

fGridHeights

protected CoffeeTable.Grid.RunVector fGridHeights

fColRatios

protected java.util.Vector fColRatios
Constructor Detail

GridPrinterBase

public GridPrinterBase(java.lang.String title)
Constructs a new empty GridPrinterBase Object.
Parameters:
title - a String specifying the report title

GridPrinterBase

public GridPrinterBase(java.lang.String title,
                       GridPanelInterface grid)
Constructs a new empty GridPrinterBase Object for the specified Grid.
Parameters:
title - a String specifying the report title
grid - the Grid being printed
Method Detail

setGrid

public void setGrid(GridPanelInterface grid)
Set the Grid to be printed.
Parameters:
grid - a reference to the GridPanel that is to be printed.

getGrid

public GridPanelInterface getGrid()
Returns the Grid associated with this GridPrinter object.
Returns:
the Grid being printed

setPrintBorder

public void setPrintBorder(boolean printBorder)
Set the flag to enable or disable the printing of a border around the page boundary. Default value: false
Parameters:
printBorder - a boolean value to enable or disable printing a border

getPrintBorder

public boolean getPrintBorder()
Check if printing a border around a page boundary is enabled.
Returns:
true if border printing is enabled

setTitle

public void setTitle(java.lang.String title)
Set the title for this report. This title is printed in the default print header.
Parameters:
title - a String specifying the title

getTitle

public java.lang.String getTitle()
Return the title for this report.
Returns:
a String specifying the title

setAutoResizeColumns

public void setAutoResizeColumns(boolean autoResizeColumns)
Set the flag to automatically resize all columns proportionally to fit on a page. If you don't specify this setting the Grid's behaviour will be inherited i.e. the columns will be resized if the AUTO_RESIZE_COLS feature is set. If specified, the Grid's setting will be overridden.
Parameters:
autoResizeColumns - a boolean value to specify whether or not to automatically resize columns to fit in a page

isAutoResizeColumns

public boolean isAutoResizeColumns()
Check if automatically resizing columns to fit in a page is enabled.
Returns:
true if the setting to automatically resizing columns is enabled

setAutoResizeRows

public void setAutoResizeRows(boolean autoResizeRows)
Set the flag to automatically resize row heights based on the cell text and column width if WORD_WRAP is enabled for any of the cells. If you don't specify this setting the Grid's behaviour will be inherited i.e. the row heights will be resized if the AUTO_RESIZE_ROWS feature is set. If specified, the Grid's setting will be overridden.
Parameters:
autoResizeRows - a boolean value to specify whether or not to automatically resize rows based on text

isAutoResizeRows

public boolean isAutoResizeRows()
Check if the feature to automatically resize rows is enabled.
Returns:
true if the setting to automatically resize rows is enabled

setPrintColHeaders

public void setPrintColHeaders(boolean printColHeaders)
Set the flag to enable or disable the printing of column headers. This setting will override the Grid's settings if specified. Default value: true
Parameters:
printColHeaders - a boolean value to enable or disable printing column headers

getPrintColHeaders

public boolean getPrintColHeaders()
Check if printing column headers is enabled.
Returns:
true if printing column headers is enabled

setPrintRowHeaders

public void setPrintRowHeaders(boolean printRowHeaders)
Set the flag to enable or disable the printing of row headers. This setting will override the Grid's settings if specified. Default value: false
Parameters:
printRowHeaders - a boolean value to enable or disable printing row headers

getPrintRowHeaders

public boolean getPrintRowHeaders()
Check if printing row headers is enabled.
Returns:
true if printing row headers is enabled

setPrintColLines

public void setPrintColLines(boolean printColLines)
Set the flag to enable or disable the printing of column lines. This setting will override the Grid's settings if specified. Default value: false
Parameters:
printColLines - a boolean value to enable or disable printing column lines

getPrintColLines

public boolean getPrintColLines()
Check if printing column lines is specified.
Returns:
true if printing column lines is enabled

setPrintRowLines

public void setPrintRowLines(boolean printRowLines)
Set the flag to enable or disable the printing of row lines. This setting will override the Grid's settings if specified. Default value: false
Parameters:
printRowLines - a boolean value to enable or disable printing row lines

getPrintRowLines

public boolean getPrintRowLines()
Check if printing row lines is specified.
Returns:
true if printing row lines is enabled

setPrintAlignment

public void setPrintAlignment(int printAlignment)
Set the print alignment. This setting specifies how the Grid is aligned on the printed page.
Parameters:
printAlignment - the page alignment (TOP_LEFT or CENTER)

getPrintAlignment

public int getPrintAlignment()
Returns the current print alignment.
Returns:
the page alignment

setPageHeaderHeight

public void setPageHeaderHeight(int headerHeight)
Set the height for the page header. Setting this value to 0 will disable printing a page header on each page. Default value: 36 (1/2 inch)
Parameters:
headerHeight - page header height
See Also:
printHeader(java.awt.Graphics, int, java.awt.Rectangle)

getPageHeaderHeight

public int getPageHeaderHeight()
Returns the page header height
Returns:
the header height

setPageFooterHeight

public void setPageFooterHeight(int footerHeight)
Set the height for the page footer. Setting this value to 0 will disable printing a page footer on each page. Default value: 36 (1/2 inch)
Parameters:
footerHeight - page footer height
See Also:
printFooter(java.awt.Graphics, int, java.awt.Rectangle)

getPageFooterHeight

public int getPageFooterHeight()
Returns the page footer height
Returns:
the footer height

setPageRange

public void setPageRange(int startPage,
                         int endPage)
Set the range of pages to be printed. Setting the values to 0 prints all pages. Default value: 0 (print all pages)
Parameters:
startPage - the first page to be printed
endPage - the last page to be printed

getNumPages

public int getNumPages()
Return the total number of pages to be printed.
Returns:
the number of pages being printed

getPrintableArea

public java.awt.Rectangle getPrintableArea()
Returns the printable area of a page.
Returns:
the page's printable area

setPrintableArea

public void setPrintableArea(java.awt.Rectangle printableArea)
Set the printable area of the page. This Rectangle should take into account the pages margins and origin. Default value is (0, 0, pageDim.width-72, pageDim.height-72)
Parameters:
printableArea - a Rectangle specifying the printable area of a page

setColWidths

public void setColWidths(int[] colWidths)
Set the column widths for this report. This setting can be used to override the Grid's existing column widths with values suitable for printing.
Parameters:
colWidths - a array of ints specifying the column widths printed report

getPageArea

public java.awt.Rectangle getPageArea()
Returns the printable area for the grid on a page after calculating it based on the printable area of the page, taking the page header and footer dimensions into consideration.
Returns:
the printable area for the grid

getColWidth

public int getColWidth(int col)
Return the width for a column. This method is called by the GridPrinter to determine the print time column widths. The default implementation returns the GridPrinter's column widths if specified, otherwise it returns the column widths by getting it from the GridPanel object.
Parameters:
col - the column
Returns:
the column width for the specified column

getRowHeight

public int getRowHeight(int row)
Return the height for a row. This method is called by the GridPrinter to determine the print time row heights. The default implementation returns the GridPrinter's row heights if specified, otherwise it returns the row height by getting it from the GridPanel object.
Parameters:
row - the row
Returns:
the row height for the specified row

getColWidths

protected int getColWidths(int startCol,
                           int numCols)

getRowHeights

protected int getRowHeights(int startRow,
                            int numRows)

calcPageAreas

protected void calcPageAreas()

calcPages

protected void calcPages()

calcRowHeight

protected final int calcRowHeight(int row)

calcColWidths

protected void calcColWidths()

calcRowHeights

protected void calcRowHeights()

calcColRange

protected int calcColRange(int fromCol)

calcRowRange

protected int calcRowRange(int fromRow)

printHeader

public void printHeader(java.awt.Graphics pg,
                        int page,
                        java.awt.Rectangle headerRect)
Prints the page header. The default implementation prints the report title at the top/center of the page header. The method can be overridden to customize printing the page header.
Parameters:
pg - the PrintGraphics object
page - the current page being printed
headerRect - the area for the header

printFooter

public void printFooter(java.awt.Graphics pg,
                        int page,
                        java.awt.Rectangle footerRect)
Prints the page footer. The default implementation prints the page number at the bottom/center of the page footer. The method can be overridden to customize printing the page footer.
Parameters:
pg - the PrintGraphics object
page - the current page being printed
footerRect - the area for the footer

printPage

public void printPage(java.awt.Graphics pg,
                      int page,
                      int fromRow,
                      int toRow,
                      int fromCol,
                      int toCol,
                      java.awt.Rectangle pageRect)
Prints the Grid data. The default implementation prints the Grid data in text or graphics mode based on the printMode setting. The method can be overridden to customize printing the page footer.
Parameters:
pg - the PrintGraphics object
page - the current page being printed
fromRow - the first row printed on this page
toRow - the last row printed on this page
fromCol - the first column printed on this page
toCol - the last column printed on this page
pageRect - the area for the page

drawIntersection

public void drawIntersection(java.awt.Graphics pg,
                             java.awt.Rectangle aRect)
Print the area in the intersection between the row and column headers. The default implementation of this method calls the Grid's drawIntersection() method. You can override this method to customize any printing behaviour.
Parameters:
pg - the graphics context to use for printing
aRect - the Rectangle for the intersection area
See Also:
GridPanelInterface.drawIntersection(java.awt.Graphics, java.awt.Rectangle)

drawHeaderCol

public void drawHeaderCol(java.awt.Graphics pg,
                          int col,
                          java.awt.Rectangle aRect)
Print the header for a column. The default implementation of this method calls the Grid's drawHeaderCol() method. You can override this method to customize any printing behaviour.
Parameters:
pg - the graphics context to use for printing
col - the column whose header is being printed
aRect - the Rectangle for the column header area
See Also:
GridPanelInterface.drawHeaderCol(java.awt.Graphics, int, java.awt.Rectangle)

drawHeaderRow

public void drawHeaderRow(java.awt.Graphics pg,
                          int row,
                          java.awt.Rectangle aRect)
Print the header for a row. The default implementation of this method calls the Grid's drawHeaderRow() method. You can override this method to customize any printing behaviour.
Parameters:
pg - the graphics context to use for printing
row - the row whose header is being printed
aRect - the Rectangle for the row header area
See Also:
GridPanelInterface.drawHeaderRow(java.awt.Graphics, int, java.awt.Rectangle)

drawCell

public void drawCell(java.awt.Graphics pg,
                     java.awt.Point cell,
                     java.awt.Rectangle cellRect)
Print the cell. The default implementation of this method calls the Grid's drawCell() method. You can override this method to customize any printing behaviour.
Parameters:
pg - the graphics context to use for printing
cell - the cell being printed
cellRect - the Rectangle for the cell area
See Also:
GridPanelInterface.drawCell(java.awt.Graphics, java.awt.Point, java.awt.Rectangle, boolean)