ReportCat 1.1

li.netcat.print.table
Class TablePrint

java.lang.Object
  extended byli.netcat.print.table.TablePrint
All Implemented Interfaces:
Print

public class TablePrint
extends java.lang.Object
implements Print

Implementation of a table with the following features:

The calculation of the table column widths and the row heights is done in three steps. Each step has a default implementation and can be replaced by a custom implementation. The first step is done by the ColumnWidthCalculator that calculates the minimum, preferred and maximum widths of the columns. At this point, the available width is assumed to be infinite. The second step is done by the ColumnWidthDistributor. It calculates the definitive widths of the columns using the results of the ColumnWidthCalculator and the available width of the table. The third step is done by the RowHeightCalculator that computes the heights of the rows using the definitive widths of the columns.

Author:
Arthur Marxer

Field Summary
static int CONSTRAINT_MIN_CELLS
          Specify this flag as a column constraint so that the column is at least as wide as the maximum preferred width of the cells.
static int CONSTRAINT_MIN_FOOTER
          Specify this flag as a column constraint so that the column is at least as wide as the preferred width of the footer.
static int CONSTRAINT_MIN_HEADER
          Specify this flag as a column constraint so that the column is at least as wide as the preferred width of the header.
 
Constructor Summary
TablePrint(TableDataModel model)
          Constructs and initializes a new TablePrint with the given data model.
 
Method Summary
 DefaultTableCellDrawer createDefaultCellDrawer(int horizontalAlignment)
          Factory method, that creates a new DefaultTableCellDrawer for the data cells.
 DefaultTableCellDrawer createDefaultFooterDrawer(int horizontalAlignment)
          Factory method, that creates a new DefaultTableCellDrawer for the footer cells.
 DefaultTableCellDrawer createDefaultHeaderDrawer(int horizontalAlignment)
          Factory method, that creates a new DefaultTableCellDrawer for the header.
 TableCellDrawer getCellDrawer(java.lang.Object type)
          Returns the data cell drawer for a given type.
 boolean getClipCells()
          Specifies, whether the table clips the cells on painting.
 float getColumnWeight(int columnIndex)
          Returns the weight of a column.
 float[] getColumnWeights()
          Returns a copy of the current column weights.
 ColumnWidthCalculator getColumnWidthCalculator()
          Returns the current column width calculator.
 int getColumnWidthConstraint(int columnIndex)
          Returns the column width costraint for a given column.
 ColumnWidthDistributor getColumnWidthDistributor()
          Returns the current column width distribution strategy.
 boolean getFitWidth()
          Specifies, whether the table should consume the whole available width.
 TableCellDrawer getFooterDrawer(java.lang.Object type)
          Returns the footer cell drawer for a given type.
 TableCellDrawer getHeaderDrawer(java.lang.Object type)
          Returns the header cell drawer for a given type.
 TableLook getLook()
          Returns the current look of the table.
 int getMinimumColumnWidth(int columnIndex)
          Returns the minimum column width for a given column.
 int getMinNrOfRows()
          Specifies the minimum number of rows that must be present before or after a break.
 TableDataModel getModel()
          Returns the data model of the table.
 java.awt.Dimension getPreferredSize(java.awt.Graphics g)
          Returns the preferred size of the Print.
 PrintIterator getPrintIterator()
          Factory method, that produces a PrintIerator.
 RowHeightCalculator getRowHeightCalculator()
          Returns the current row height calculator.
 void setCellDrawer(java.lang.Object type, TableCellDrawer drawer)
          Sets a custom data cell drawer for a specific type.
 void setClipCells(boolean clipCells)
          Specifies, whether the table clips the cells on painting.
 void setColumnWeight(int columnIndex, float weight)
          Sets the weight of a specific column.
 void setColumnWidthCalculator(ColumnWidthCalculator calculator)
          Sets a new strategy that calculates the column widths.
 void setColumnWidthConstraint(int columnIndex, int constraint)
          Sets the column width constraint for a given column of the table.
 void setColumnWidthDistributor(ColumnWidthDistributor distributor)
          Sets a new strategy that distributes the available width of the table among the columns.
 void setDefaultCellDrawer(TableCellDrawer drawer)
          Sets the default data cell drawer that is used, when no custom drawer is found.
 void setDefaultFooterDrawer(TableCellDrawer drawer)
          Sets the default footer cell drawer that is used, when no custom drawer is found.
 void setDefaultHeaderDrawer(TableCellDrawer drawer)
          Sets the default header cell drawer that is used, when no custom drawer is found.
static void setDefaultLook(TableLook look)
          Sets the default table look.
 void setFitWidth(boolean fitWidth)
          Specifies, whether the table should consume the whole available width.
 void setFooterDrawer(java.lang.Object type, TableCellDrawer drawer)
          Sets a custom footer cell drawer for a specific type.
 void setHeaderDrawer(java.lang.Object type, TableCellDrawer drawer)
          Sets a custom header cell drawer for a specific type.
 void setLook(TableLook look)
          Sets a custom look for the table.
 void setMinimumColumnWidth(int columnIndex, int minimumWidth)
          Sets the minimum column width in pixel for a given column.
 void setMinNrOfRows(int nr)
          Sets the minimum number of rows that must be present before or after a break.
 void setModel(TableDataModel model)
          Sets the data model of the table.
 void setRowHeightCalculator(RowHeightCalculator calculator)
          Sets a new strategy that calculates the row heights.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CONSTRAINT_MIN_HEADER

public static final int CONSTRAINT_MIN_HEADER
Specify this flag as a column constraint so that the column is at least as wide as the preferred width of the header.

See Also:
setColumnWidthConstraint(int, int), Constant Field Values

CONSTRAINT_MIN_CELLS

public static final int CONSTRAINT_MIN_CELLS
Specify this flag as a column constraint so that the column is at least as wide as the maximum preferred width of the cells.

See Also:
setColumnWidthConstraint(int, int), Constant Field Values

CONSTRAINT_MIN_FOOTER

public static final int CONSTRAINT_MIN_FOOTER
Specify this flag as a column constraint so that the column is at least as wide as the preferred width of the footer.

See Also:
setColumnWidthConstraint(int, int), Constant Field Values
Constructor Detail

TablePrint

public TablePrint(TableDataModel model)
Constructs and initializes a new TablePrint with the given data model.

Parameters:
model - The data model, not null.
Method Detail

setDefaultLook

public static void setDefaultLook(TableLook look)
Sets the default table look. After this call, all calls to the constructor will use this table look.

Parameters:
look - A custom table look, not null.

getModel

public TableDataModel getModel()
Returns the data model of the table.

Returns:
The data model of the table.

setModel

public void setModel(TableDataModel model)
Sets the data model of the table.

Parameters:
model - The data model of the table, not null.

getLook

public TableLook getLook()
Returns the current look of the table.

Returns:
The current look of the table.

setLook

public void setLook(TableLook look)
Sets a custom look for the table.

Parameters:
look - A custom look, not null.

getCellDrawer

public TableCellDrawer getCellDrawer(java.lang.Object type)
Returns the data cell drawer for a given type. Note that the type of a cell is defined by the data model.

Parameters:
type - The type of the data cell.
Returns:
The data cell drawer for the given type.

setCellDrawer

public void setCellDrawer(java.lang.Object type,
                          TableCellDrawer drawer)
Sets a custom data cell drawer for a specific type. Note that the type of a cell is defined by the data model.

Parameters:
type - The type of the data cell.
drawer - A custom data cell drawer.

setDefaultCellDrawer

public void setDefaultCellDrawer(TableCellDrawer drawer)
Sets the default data cell drawer that is used, when no custom drawer is found.

Parameters:
drawer - The new default data cell drawer, not null.

getHeaderDrawer

public TableCellDrawer getHeaderDrawer(java.lang.Object type)
Returns the header cell drawer for a given type. Note that the type of a cell is defined by the data model.

Parameters:
type - The type of the header cell.
Returns:
The header cell drawer for the given type.

setHeaderDrawer

public void setHeaderDrawer(java.lang.Object type,
                            TableCellDrawer drawer)
Sets a custom header cell drawer for a specific type. Note that the type of a cell is defined by the data model.

Parameters:
type - The type of the header cell.
drawer - A custom header cell drawer.

setDefaultHeaderDrawer

public void setDefaultHeaderDrawer(TableCellDrawer drawer)
Sets the default header cell drawer that is used, when no custom drawer is found.

Parameters:
drawer - The new default header cell drawer, not null.

getFooterDrawer

public TableCellDrawer getFooterDrawer(java.lang.Object type)
Returns the footer cell drawer for a given type. Note that the type of a cell is defined by the data model.

Parameters:
type - The type of the footer cell.
Returns:
The footer cell drawer for the given type.

setFooterDrawer

public void setFooterDrawer(java.lang.Object type,
                            TableCellDrawer drawer)
Sets a custom footer cell drawer for a specific type. Note that the type of a cell is defined by the data model.

Parameters:
type - The type of the footer cell.
drawer - A custom footer cell drawer.

setDefaultFooterDrawer

public void setDefaultFooterDrawer(TableCellDrawer drawer)
Sets the default footer cell drawer that is used, when no custom drawer is found.

Parameters:
drawer - The new default footer cell drawer, not null.

getColumnWeight

public float getColumnWeight(int columnIndex)
Returns the weight of a column. This weight is typically used to "rewidth" the table.

Parameters:
columnIndex - The index of the column.

getColumnWeights

public float[] getColumnWeights()
Returns a copy of the current column weights.

Returns:
A copy of the current column weights.

setColumnWeight

public void setColumnWeight(int columnIndex,
                            float weight)
Sets the weight of a specific column. This weight is typically used to "rewidth" the table.

Parameters:
columnIndex - The index of the column.
weight - The weight of the column, >= 0.0f.

getMinimumColumnWidth

public int getMinimumColumnWidth(int columnIndex)
Returns the minimum column width for a given column.

Parameters:
columnIndex - The index of the column.
Returns:
The minimum column width for the given column.

setMinimumColumnWidth

public void setMinimumColumnWidth(int columnIndex,
                                  int minimumWidth)
Sets the minimum column width in pixel for a given column. Use the setColumnWidthConstaint() method, if you want to set the minimum column width to the preferred width of a cell.

Parameters:
columnIndex - The index of the column.
minimumWidth - The minimum width of the column.
See Also:
setColumnWidthConstraint(int, int)

getColumnWidthConstraint

public int getColumnWidthConstraint(int columnIndex)
Returns the column width costraint for a given column.

Returns:
A combination of the flags CONSTRAINT_*.

setColumnWidthConstraint

public void setColumnWidthConstraint(int columnIndex,
                                     int constraint)
Sets the column width constraint for a given column of the table. This constraint can be used for example to set the minimum column width to the preferred header width.

Parameters:
columnIndex - The index of the column.
constraint - A combination of the flags CONSTRAINT_*.

getFitWidth

public boolean getFitWidth()
Specifies, whether the table should consume the whole available width.

Returns:
true, if the table should consume the whole available width. The default is false.

setFitWidth

public void setFitWidth(boolean fitWidth)
Specifies, whether the table should consume the whole available width.

Parameters:
fitWidth - Specify true, if the table should consume the whole available width. The default is false.

getClipCells

public boolean getClipCells()
Specifies, whether the table clips the cells on painting.

Returns:
true, if the table clips the cells on painting. The default is true.

setClipCells

public void setClipCells(boolean clipCells)
Specifies, whether the table clips the cells on painting.

Parameters:
clipCells - Specify true, if the table shoud clip the cells on painting. The default is true.

getMinNrOfRows

public int getMinNrOfRows()
Specifies the minimum number of rows that must be present before or after a break.

Returns:
The minimum number of rows before or after a break.

setMinNrOfRows

public void setMinNrOfRows(int nr)
Sets the minimum number of rows that must be present before or after a break.

Parameters:
nr - The minimum number of rows before or after a break. This value must be >= 1.

createDefaultHeaderDrawer

public DefaultTableCellDrawer createDefaultHeaderDrawer(int horizontalAlignment)
Factory method, that creates a new DefaultTableCellDrawer for the header.

Parameters:
horizontalAlignment - One of LEFT, CENTER or RIGHT.
Returns:
A new instance of a DefaultTableCellDrawer.

createDefaultCellDrawer

public DefaultTableCellDrawer createDefaultCellDrawer(int horizontalAlignment)
Factory method, that creates a new DefaultTableCellDrawer for the data cells.

Parameters:
horizontalAlignment - One of LEFT, CENTER or RIGHT.
Returns:
A new instance of a DefaultTableCellDrawer.

createDefaultFooterDrawer

public DefaultTableCellDrawer createDefaultFooterDrawer(int horizontalAlignment)
Factory method, that creates a new DefaultTableCellDrawer for the footer cells.

Parameters:
horizontalAlignment - One of LEFT, CENTER or RIGHT.
Returns:
A new instance of a DefaultTableCellDrawer.

getColumnWidthCalculator

public ColumnWidthCalculator getColumnWidthCalculator()
Returns the current column width calculator.

Returns:
The current column width calculator strategy, not not null.

setColumnWidthCalculator

public void setColumnWidthCalculator(ColumnWidthCalculator calculator)
Sets a new strategy that calculates the column widths.

Parameters:
calculator - An implementation of the ColumnWidthCalculator, not null.

getColumnWidthDistributor

public ColumnWidthDistributor getColumnWidthDistributor()
Returns the current column width distribution strategy.

Returns:
The current column width distribution strategy, not not null.

setColumnWidthDistributor

public void setColumnWidthDistributor(ColumnWidthDistributor distributor)
Sets a new strategy that distributes the available width of the table among the columns.

Parameters:
distributor - An implementation of the ColumnWidthDistributor, not null.

getRowHeightCalculator

public RowHeightCalculator getRowHeightCalculator()
Returns the current row height calculator.

Returns:
The current row height calculator strategy, not not null.

setRowHeightCalculator

public void setRowHeightCalculator(RowHeightCalculator calculator)
Sets a new strategy that calculates the row heights.

Parameters:
calculator - An implementation of the RowHeightCalculator, not null.

getPreferredSize

public java.awt.Dimension getPreferredSize(java.awt.Graphics g)
Description copied from interface: Print
Returns the preferred size of the Print.

Specified by:
getPreferredSize in interface Print
Parameters:
g - The relevant Graphics object. It can be used to calculate the widths of strings.
Returns:
The preferred size of the Print.

getPrintIterator

public PrintIterator getPrintIterator()
Description copied from interface: Print
Factory method, that produces a PrintIerator. The PrintIterator is used like an enumeration to generate all Prints.

Specified by:
getPrintIterator in interface Print
Returns:
An instance of a PrintIterator that is able to iterate over the Print.

ReportCat 1.1

Copyright 2003 - 2005 NetCat Inc.. All rights reserved. Feedback

Print,Printing,Printer,Java,Java Print,SDK,Java Printing,Printing Java,Print Java,Library,Java Library,Print Library,Report,Reports,Java Report,Java Programming,Java Output,Layout,Page,API,Preview,Print Preview,Content,A4,Free,Output,Header,Footer,Download,Package,Jar,Evaluation, Print,Printing,Printer,Java,Java Print,SDK,Java Printing,Printing Java,Print Java,Library,Java Library,Print Library,Report,Reports,Java Report,Java Programming,Java Output,Layout,Page,API,Preview,Print Preview,Content,A4,Free,Output,Header,Footer,Download,Package,Jar,Evaluation, Print,Printing,Printer,Java,Java Print,SDK,Java Printing,Printing Java,Print Java,Library,Java Library,Print Library,Report,Reports,Java Report,Java Programming,Java Output,Layout,Page,API,Preview,Print Preview,Content,A4,Free,Output,Header,Footer,Download,Package,Jar,Evaluation