Class GridPrint
- All Implemented Interfaces:
Print
public final class GridPrint extends java.lang.Object implements Print
GridPrint uses a column sizing algorithm based on the W3C
recommendation for automatic layout of tables. GridPrint deviates from
the recommendation on one important point: if there is less width available
on the print device than the calculated "minimum" size of the grid, the
columns will be scaled down to less than their calculated minimum
widths. Only when one of the columns goes below its "absolute minimum" will
the grid fail to print ( PrintIterator.next(int, int)
returns null).
GridPrint offers three basic methods of specifying column size.
- Default size. The column will be somewhere between it's minimum and preferred width. GridPrint will determine the optimum widths for all default size columns, using the modified W3C recommendation described above. This is the recommended option for most cases.
- Preferred size. The column will be sized to it's preferred width. This option is sometimes appropriate, for example when certain portions of text should not be allowed to line-wrap. In cases where only a few cells in a column need to be prevented from line wrapping, consider wrapping them in a NoBreakPrint instead.
- Explicit size. The column will be the size you specify, expressed in points. 72 points = 1".
In addition, any column can be given a grow attribute. In the event a grid is not as wide as the page, those columns with the grow attribute set will be widened to fill the extra space.
Because GridPrint scales columns according to their minimum sizes in the worst-case scenario, the absolute minimum size of a GridPrint is dependant on its child prints and is not clearly defined.
If a grid has one of more columns with the grow attribute set, the grid is horizontally greedy. Greedy prints take up all the available space on the page.
-
Field Summary
Fields Modifier and Type Field Description (package private) java.util.List<java.util.List<GridCell>>
body
Two-dimensional list of all body cells.static int
BORDER_OVERLAP
Constant cell spacing value indicating that the borders of adjacent cells should overlap.(package private) boolean
cellClippingEnabled
(package private) int[][]
columnGroups
Array of column groups.(package private) java.util.List<GridColumn>
columns
The columns for this grid.(package private) java.util.List<java.util.List<GridCell>>
footer
Two-dimension list of all footer cells.(package private) java.util.List<java.util.List<GridCell>>
header
Two-dimension list of all header cells.static int
PREFERRED
Constant column size value indicating that the column should be given its preferred size.static int
REMAINDER
Constant colspan value indicating that all remaining columns in the row should be used. -
Constructor Summary
Constructors Constructor Description GridPrint()
Constructs a GridPrint with no columns and a default look.GridPrint(java.lang.String columns)
Constructs a GridPrint with the given columns and a default look.GridPrint(java.lang.String columns, GridLook look)
Constructs a GridPrint with the given columns and look.GridPrint(GridColumn[] columns)
Constructs a GridPrint with the given columns and a default look.GridPrint(GridColumn[] columns, GridLook look)
Constructs a GridPrint with the given columns and look.GridPrint(GridLook look)
Constructs a GridPrint with no columns and the given look. -
Method Summary
Modifier and Type Method Description void
add(int hAlignment, int vAlignment, Print cell)
Adds the Print to the grid body, using the given colspan and alignment.void
add(int hAlignment, int vAlignment, Print cell, int colspan)
Adds the Print to the grid body, using the given colspan and alignment.void
add(int hAlignment, Print cell)
Adds the Print to the grid body, using the given colspan and alignment.void
add(int hAlignment, Print cell, int colspan)
Adds the Print to the grid body, using the given colspan and alignment.void
add(Print cell)
Adds the Print to the grid body, with the default alignment and a colspan of 1.void
add(Print cell, int colspan)
Adds the Print to the grid body, with the given colspan and the default alignment.void
addColumn(int index, java.lang.String column)
Inserts the column at the specified position in the grid.void
addColumn(int index, GridColumn column)
Inserts the column at the specified position in the grid.void
addColumn(java.lang.String column)
Adds the column on the right edge of the grid.void
addColumn(GridColumn column)
Adds the column on the right edge of the grid.void
addColumns(int index, java.lang.String columns)
Inserts the columns at the specified position in the grid.void
addColumns(int index, GridColumn[] columns)
Inserts the columns at the specified position in the grid.void
addColumns(java.lang.String columns)
Adds the columns on the right edge of the grid.void
addColumns(GridColumn[] columns)
Adds the columns on the right edge of the grid.void
addFooter(int hAlignment, int vAlignment, Print cell)
Adds the Print to the grid footer, using the given colspan and alignment.void
addFooter(int hAlignment, int vAlignment, Print cell, int colspan)
Adds the Print to the grid footer, using the given colspan and alignment.void
addFooter(int hAlignment, Print cell)
Adds the Print to the grid footer, using the given colspan and alignment.void
addFooter(int hAlignment, Print cell, int colspan)
Adds the Print to the grid footer, using the given colspan and alignment.void
addFooter(Print cell)
Adds the Print to the grid footer, with the default alignment and a colspan of 1.void
addFooter(Print cell, int colspan)
Adds the Print to the grid footer, with the given colspan and the default alignment.void
addHeader(int hAlignment, int vAlignment, Print cell)
Adds the Print to the grid header, using the given alignment.void
addHeader(int hAlignment, int vAlignment, Print cell, int colspan)
Adds the Print to the grid header, using the given colspan and alignment.void
addHeader(int hAlignment, Print cell)
Adds the Print to the grid header, using the given alignment.void
addHeader(int hAlignment, Print cell, int colspan)
Adds the Print to the grid header, using the given colspan and alignment.void
addHeader(Print cell)
Adds the Print to the grid header, with default alignment and a colspan of 1.void
addHeader(Print cell, int colspan)
Adds the Print to the grid header, with the given colspan and the default alignment.boolean
equals(java.lang.Object obj)
GridCell[][]
getBodyCells()
Returns an array containing the body cells in the grid.int[][]
getColumnGroups()
Returns current column groups.GridColumn[]
getColumns()
Returns an array ofGridColumn
s which are the columns in the receiver.GridCell[][]
getFooterCells()
Returns an array containing the footer cells in the grid.GridCell[][]
getHeaderCells()
Returns an array containing the header cells in this grid.GridLook
getLook()
Returns the grid's look.int
hashCode()
boolean
isCellClippingEnabled()
Returns whether individual body cells in the grid may be broken across pages.PrintIterator
iterator(org.eclipse.swt.graphics.Device device, org.eclipse.swt.graphics.GC gc)
Returns a PrintIterator for laying out the contents of this Print.void
setCellClippingEnabled(boolean cellClippingEnabled)
Sets whether individual body cells in the grid may be broken across pages.void
setColumnGroups(int[][] columnGroups)
Sets the column groups to the given two-dimension array.void
setLook(GridLook look)
Sets the grid's look.
-
Field Details
-
REMAINDER
public static final int REMAINDERConstant colspan value indicating that all remaining columns in the row should be used.- See Also:
- Constant Field Values
-
PREFERRED
public static final int PREFERREDConstant column size value indicating that the column should be given its preferred size. (In the context of W3C's autolayout recommendation, this has the effect of setting the columns minimum width to its preferred width. This value is used in the GridColumn constructor.- See Also:
- Constant Field Values
-
BORDER_OVERLAP
public static final int BORDER_OVERLAPConstant cell spacing value indicating that the borders of adjacent cells should overlap.- See Also:
- Constant Field Values
-
columns
The columns for this grid. -
columnGroups
int[][] columnGroupsArray of column groups. -
header
Two-dimension list of all header cells. Each element of this list represents a row in the header. Each element of a row represents a cellspan in that row. -
body
Two-dimensional list of all body cells. Each element of this list represents a row in the body. Each element of a row represents a cellspan in that row. -
cellClippingEnabled
boolean cellClippingEnabled -
footer
Two-dimension list of all footer cells. Each element of this list represents a row in the footer. Each element of a row represents a cellspan in that row.
-
-
Constructor Details
-
GridPrint
public GridPrint()Constructs a GridPrint with no columns and a default look. -
GridPrint
Constructs a GridPrint with no columns and the given look.- Parameters:
look
- the look to apply to the constructed grid.
-
GridPrint
public GridPrint(java.lang.String columns)Constructs a GridPrint with the given columns and a default look.- Parameters:
columns
- a comma-separated list of parseable column specs.- See Also:
GridColumn.parse(String)
-
GridPrint
Constructs a GridPrint with the given columns and look.- Parameters:
columns
- a comma-separated list of parseable column specs.look
- the look to apply to the constructed grid.- See Also:
GridColumn.parse(String)
-
GridPrint
Constructs a GridPrint with the given columns and a default look.- Parameters:
columns
- the columns for the new grid.
-
GridPrint
Constructs a GridPrint with the given columns and look.- Parameters:
columns
- the columns for the new grid.look
- the look to apply to the constructed grid.
-
-
Method Details
-
hashCode
public int hashCode()- Overrides:
hashCode
in classjava.lang.Object
-
equals
public boolean equals(java.lang.Object obj)- Overrides:
equals
in classjava.lang.Object
-
addColumn
public void addColumn(java.lang.String column)Adds the column on the right edge of the grid. Any cells which have been added to the grid prior to adding the column will be adjusted as follows: the right-hand cell of each completed row will have it's colspan expanded to fill the added column.- Parameters:
column
- the column to add to the grid.- See Also:
GridColumn.parse(String)
-
addColumn
Adds the column on the right edge of the grid. Any cells which have been added to the grid prior to adding the column will be adjusted as follows: the right-hand cell of each completed row will have it's colspan expanded to fill the added column.- Parameters:
column
- the column to add to the grid.
-
addColumn
public void addColumn(int index, java.lang.String column)Inserts the column at the specified position in the grid. Any cells which have been added to the grid prior to adding the column will be adjusted as follows: on each row, the cell which overlaps or whose right edge touches the insert position will be expanded to fill the added column.- Parameters:
index
- the insert position.column
- the column to be inserted.- See Also:
GridColumn.parse(String)
-
addColumn
Inserts the column at the specified position in the grid. Any cells which have been added to the grid prior to adding the column will be adjusted as follows: on each row, the cell which overlaps or whose right edge touches the insert position will be expanded to fill the added column.- Parameters:
index
- the insert position.column
- the column to be inserted.
-
addColumns
public void addColumns(java.lang.String columns)Adds the columns on the right edge of the grid. Any cells which have been added to the grid prior to adding the columns will be adjusted as follows: the right-hand cell of each completed row will have it's colspan expanded to fill the added columns.- Parameters:
columns
- the columns to add to the grid.- See Also:
GridColumn.parse(String)
-
addColumns
Adds the columns on the right edge of the grid. Any cells which have been added to the grid prior to adding the columns will be adjusted as follows: the right-hand cell of each completed row will have it's colspan expanded to fill the added columns.- Parameters:
columns
- the columns to add to the grid.
-
addColumns
public void addColumns(int index, java.lang.String columns)Inserts the columns at the specified position in the grid. Any cells which have been added to the grid prior to adding the columns will be adjusted as follows: on each row, the cell which overlaps or whose right edge touches the insert position will be expanded to fill the added columns.- Parameters:
index
- the insert position.columns
- the columns to be inserted.- See Also:
GridColumn.parse(String)
-
addColumns
Inserts the columns at the specified position in the grid. Any cells which have been added to the grid prior to adding the columns will be adjusted as follows: on each row, the cell which overlaps or whose right edge touches the insert position will be expanded to fill the added columns.- Parameters:
index
- the insert position.columns
- the columns to be inserted.- See Also:
GridColumn.parse(String)
-
getColumns
Returns an array ofGridColumn
s which are the columns in the receiver.- Returns:
- an array of
GridColumn
s which are the columns in the receiver.
-
addHeader
Adds the Print to the grid header, with default alignment and a colspan of 1.- Parameters:
cell
- the print to add.
-
addHeader
Adds the Print to the grid header, using the given alignment.- Parameters:
hAlignment
- the horizontal alignment of the print within the grid cell. One ofSWT.DEFAULT
,SWT.LEFT
,SWT.CENTER
orSWT.RIGHT
.cell
- the print to add.
-
addHeader
Adds the Print to the grid header, using the given alignment.- Parameters:
hAlignment
- the horizontal alignment of the print within the grid cell. One ofSWT.DEFAULT
,SWT.LEFT
,SWT.CENTER
orSWT.RIGHT
.vAlignment
- the vertical alignment of the print within the grid cell. One ofSWT.DEFAULT
,SWT.TOP
,SWT.CENTER
,SWT.BOTTOM
, orSWT.FILL
. A value of FILL indicates that the cell is vertically greedy, so GridPrint will limit the cell's height to the tallest non-FILL cell in the row.cell
- the print to add.
-
addHeader
Adds the Print to the grid header, with the given colspan and the default alignment.- Parameters:
cell
- the print to add.colspan
- the number of columns to span, orREMAINDER
to span the rest of the row.
-
addHeader
Adds the Print to the grid header, using the given colspan and alignment.- Parameters:
cell
- the print to add.colspan
- the number of columns to span, orREMAINDER
to span the rest of the row.hAlignment
- the horizontal alignment of the print within the grid cell. One ofSWT.DEFAULT
,SWT.LEFT
,SWT.CENTER
orSWT.RIGHT
.
-
addHeader
Adds the Print to the grid header, using the given colspan and alignment.- Parameters:
hAlignment
- the horizontal alignment of the print within the grid cell. One ofSWT.DEFAULT
,SWT.LEFT
,SWT.CENTER
orSWT.RIGHT
.vAlignment
- the vertical alignment of the print within the grid cell. One ofSWT.DEFAULT
,SWT.TOP
,SWT.CENTER
,SWT.BOTTOM
, orSWT.FILL
. A value of FILL indicates that the cell is vertically greedy, so GridPrint will limit the cell's height to the tallest non-FILL cell in the row.cell
- the print to add.colspan
- the number of columns to span, orREMAINDER
to span the rest of the row.
-
getHeaderCells
Returns an array containing the header cells in this grid. Each inner array represents one row in the header.- Returns:
- an array containing the header cells in this grid.
-
getBodyCells
Returns an array containing the body cells in the grid. Each inner array represents one row in the body.- Returns:
- an array containing the body cells in the grid.
-
getFooterCells
Returns an array containing the footer cells in the grid. Each inner array represents one row in the footer.- Returns:
- an array containing the footer cells in the grid.
-
add
Adds the Print to the grid body, with the default alignment and a colspan of 1.- Parameters:
cell
- the print to add.
-
add
Adds the Print to the grid body, using the given colspan and alignment.- Parameters:
hAlignment
- the horizontal alignment of the print within the grid cell. One ofSWT.DEFAULT
,SWT.LEFT
,SWT.CENTER
orSWT.RIGHT
.cell
- the print to add.
-
add
Adds the Print to the grid body, using the given colspan and alignment.- Parameters:
hAlignment
- the horizontal alignment of the print within the grid cell. One ofSWT.DEFAULT
,SWT.LEFT
,SWT.CENTER
orSWT.RIGHT
.vAlignment
- the vertical alignment of the print within the grid cell. One ofSWT.DEFAULT
,SWT.TOP
,SWT.CENTER
,SWT.BOTTOM
, orSWT.FILL
. A value of FILL indicates that the cell is vertically greedy, so GridPrint will limit the cell's height to the tallest non-FILL cell in the row.cell
- the print to add.
-
add
Adds the Print to the grid body, with the given colspan and the default alignment.- Parameters:
cell
- the print to add.colspan
- the number of columns to span, orREMAINDER
to span the rest of the row.
-
add
Adds the Print to the grid body, using the given colspan and alignment.- Parameters:
hAlignment
- the horizontal alignment of the print within the grid cell. One ofSWT.DEFAULT
,SWT.LEFT
,SWT.CENTER
orSWT.RIGHT
.cell
- the print to add.colspan
- the number of columns to span, orREMAINDER
to span the rest of the row.
-
add
Adds the Print to the grid body, using the given colspan and alignment.- Parameters:
hAlignment
- the horizontal alignment of the print within the grid cell. One ofSWT.DEFAULT
,SWT.LEFT
,SWT.CENTER
orSWT.RIGHT
.vAlignment
- the vertical alignment of the print within the grid cell. One ofSWT.DEFAULT
,SWT.TOP
,SWT.CENTER
,SWT.BOTTOM
, orSWT.FILL
. A value of FILL indicates that the cell is vertically greedy, so GridPrint will limit the cell's height to the tallest non-FILL cell in the row.cell
- the print to add.colspan
- the number of columns to span, orREMAINDER
to span the rest of the row.
-
isCellClippingEnabled
public boolean isCellClippingEnabled()Returns whether individual body cells in the grid may be broken across pages. Defaults to true.- Returns:
- whether individual body cells in the grid may be broken across pages.
-
setCellClippingEnabled
public void setCellClippingEnabled(boolean cellClippingEnabled)Sets whether individual body cells in the grid may be broken across pages.- Parameters:
cellClippingEnabled
- whether to enabled cell clipping.
-
addFooter
Adds the Print to the grid footer, with the default alignment and a colspan of 1.- Parameters:
cell
- the print to add.
-
addFooter
Adds the Print to the grid footer, using the given colspan and alignment.- Parameters:
hAlignment
- the horizontal alignment of the print within the grid cell. One ofSWT.DEFAULT
,SWT.LEFT
,SWT.CENTER
orSWT.RIGHT
.cell
- the print to add.
-
addFooter
Adds the Print to the grid footer, using the given colspan and alignment.- Parameters:
hAlignment
- the horizontal alignment of the print within the grid cell. One ofSWT.DEFAULT
,SWT.LEFT
,SWT.CENTER
orSWT.RIGHT
.vAlignment
- the vertical alignment of the print within the grid cell. One ofSWT.DEFAULT
,SWT.TOP
,SWT.CENTER
,SWT.BOTTOM
, orSWT.FILL
. A value of FILL indicates that the cell is vertically greedy, so GridPrint will limit the cell's height to the tallest non-FILL cell in the row.cell
- the print to add.
-
addFooter
Adds the Print to the grid footer, with the given colspan and the default alignment.- Parameters:
cell
- the print to add.colspan
- the number of columns to span, orREMAINDER
to span the rest of the row.
-
addFooter
Adds the Print to the grid footer, using the given colspan and alignment.- Parameters:
hAlignment
- the horizontal alignment of the print within the grid cell. One ofSWT.DEFAULT
,SWT.LEFT
,SWT.CENTER
orSWT.RIGHT
.cell
- the print to add.colspan
- the number of columns to span, orREMAINDER
to span the rest of the row.
-
addFooter
Adds the Print to the grid footer, using the given colspan and alignment.- Parameters:
hAlignment
- the horizontal alignment of the print within the grid cell. One ofSWT.DEFAULT
,SWT.LEFT
,SWT.CENTER
orSWT.RIGHT
.vAlignment
- the vertical alignment of the print within the grid cell. One ofSWT.DEFAULT
,SWT.TOP
,SWT.CENTER
,SWT.BOTTOM
, orSWT.FILL
. A value of FILL indicates that the cell is vertically greedy, so GridPrint will limit the cell's height to the tallest non-FILL cell in the row.cell
- the print to add.colspan
- the number of columns to span, orREMAINDER
to span the rest of the row.
-
getColumnGroups
public int[][] getColumnGroups()Returns current column groups. The returned array may be modified without affecting this GridPrint.- Returns:
- the column groups.
-
setColumnGroups
public void setColumnGroups(int[][] columnGroups)Sets the column groups to the given two-dimension array. Each int[] array is a group. Columns in a group will be the same size when laid out on the print device.The following statement causes columns 0 and 2 to be the same size, and columns 1 and 3 to be the same size.
grid.setColumnGroups(new int[][] { { 0, 2 }, { 1, 3 } });
The behavior of this property is undefined when a column belongs to more than one group.
Note: Column grouping is enforced before column weights. Therefore, columns in the same group should be given the same weight to ensure they are laid out at the same width.
- Parameters:
columnGroups
- the new column groups.
-
getLook
Returns the grid's look. A GridLook determines what decorations will appear around the grid's contents. Default is a DefaultGridLook with no cell spacing, no cell borders, and no background colors.- Returns:
- the look of this grid.
-
setLook
Sets the grid's look.- Parameters:
look
- the new look.
-
iterator
public PrintIterator iterator(org.eclipse.swt.graphics.Device device, org.eclipse.swt.graphics.GC gc)Description copied from interface:Print
Returns a PrintIterator for laying out the contents of this Print. The iterator uses a snapshot of the print at the time this method is invoked, so subsequent changes to the Print will not affect the output of the iterator.
-