|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object pagelayout.Cell pagelayout.CellGrid
public class CellGrid
A CellGrid
is a collection of
Cell
objects
whose elements are
laid out in the container in a rectangular grid.
When a Row
object is constructed by adding to it a set of
Column
objects, the rows of the columns
may not necessarily align along the horizontal direction,
as the internal layout of each of the columns is done independently
of the other columns. So, if it is required to align the rows of
a group of columns, the CellGrid
object should be used instead of columns and rows.
A CellGrid
object is
most easily constructed by first building the rows
of the grid by using the
methods of the GridRows
class
and by calling its
createCellGrid
method.
A CellGrid
object may also be
constructed by first building
the elements of the array of cells that form the grid,
and then using one of the
createCellGrid
methods of this class.
setAlignments
may be used to specify
the vertical and horizontal alignments of each of the cells. setRowMargins
may be used to specify
the left or right margin of one or more of the rows.setColumnMargins
may be used to specify
the top or bottom margin of one or more of the columns.The two examples Example4
and Example7
illustrate the
use of a CellGrid
and the
createCellGrid
methods
of this class. Example9
illustrates a
case in which a component spans more than one column. In
Example10
a grid is created by
first constructing the rows by using the
GridRow
class.
Finally, in Example11
a grid is created by
first constructing the rows by using the
GridRows
class.
Cell
,
Column
,
Row
,
GridRow
Nested Class Summary |
---|
Nested classes/interfaces inherited from class pagelayout.Cell |
---|
Cell.Constraint |
Field Summary | |
---|---|
protected int[] |
colWidths
|
protected boolean[][] |
draw
|
static int |
DRAW
|
protected Cell[][] |
elements
|
protected byte[][] |
hspan
|
static int |
HSPAN
|
static Cell |
HSPANCELL
Cell to be inserted in a grid of cells for horizontal spanning. |
static java.awt.Component |
HSPANComponent
Component to be inserted in a grid of components for horizontal spanning. |
static int |
NULL
|
static Cell |
NULLCELL
|
protected int[] |
rowHeights
|
protected byte[][] |
vspan
|
static int |
VSPAN
|
static Cell |
VSPANCELL
Cell to be inserted in a grid of cells for vertical spanning. |
static java.awt.Component |
VSPANComponent
Component to be inserted in a grid of components for vertical spanning. |
Fields inherited from class pagelayout.Cell |
---|
BASELINE, BOTTOM, boundSpring, CENTER, constraint, filledSizeX, filledSizeY, fixMaxSize, FOUND_NOTREPLACED, FOUND_REPLACED, halign, JUSTIFIED, LEFT, links, MAX, NEWROW, NO_ALIGNMENT, NOT_FOUND, RIGHT, SKIP, TOP, valign |
Constructor Summary | |
---|---|
protected |
CellGrid(Cell[][] elements,
int m,
int n)
|
Method Summary | |
---|---|
void |
addComponentsToContainer(java.awt.Container container)
Recursively calls the addComponentsToContainer
method of each cell within the grid to add the components of the cells
to the container. |
BoundSpring |
computeBoundSpring()
Computes the two-dimensional spring associated with the grid that results from the approriate combination of the springs of the child cells. |
protected static CellGrid |
createCellGrid(Cell... cells)
|
static CellGrid |
createCellGrid(Cell[][] cellArray)
Creates a CellGrid from a two dimensional array of cells. |
static CellGrid |
createCellGrid(Cell[] cellArray,
int[] rowIndices,
int[] colIndices)
Creates a CellGrid from a one dimensional array of cells. |
static CellGrid |
createCellGrid(java.awt.Component[][] cellArray)
Creates a CellGrid from a two dimensional array of
components. |
static CellGrid |
createCellGrid(GridRow... rows)
Creates grid of cells from an array of GridRow
objects. |
protected static CellGrid |
createCellGrid(java.lang.Object... o)
|
Cell |
duplicate(ComponentDuplicator c)
|
int |
getAlignment(int i,
int j,
int coord,
int defaultValue)
|
int[][][] |
getAlignments()
|
Cell |
getCell(int rowIndex,
int columnIndex)
Returns the cell at the given row and column indices. |
Cell |
getChildAt(int index)
Return the child cell of the grid that is associated with the given (linear) index. |
int[] |
getColWidths()
|
int |
getIndex(int rowIndex,
int columnIndex)
|
int[] |
getRowHeights()
|
void |
initCellGrid(Cell[][] elements,
int m,
int n)
|
int |
numberOfChildren()
Returns the number of cells in the grid. |
int |
numberOfColumns()
Returns the number of columns in the grid. |
int |
numberOfRows()
Returns the number of rows in the grid. |
boolean |
replaceChild(int index,
Cell newCell,
java.awt.Container parent)
Replace the cell at the specified index with a new cell. |
void |
setAlignment(int rowIndex,
int columnIndex,
int halign,
int valign)
Sets the vertical and horizontal alignments of a cell in the frid. |
void |
setAlignments(int[][] halign,
int[][] valign)
This method can be use to set the horizontal and vertical alignments of each of the cells in the grid. |
protected void |
setBounds(int x,
int y,
int width,
int height)
Lays out the cells of the grid within the specified rectangle of the container. |
void |
setColumnMargins(int side,
int value,
int... columns)
Sets the height of the margins or empty space at the top or bottom of the specified columns. |
void |
setFixedColumnWidth(int[] columns)
Fixes the widths of the specified columns so they do not change even if the enclosing cell size changes. |
void |
setFixedRowHeight(int[] rows)
Fixes the heights of the specified rows so they do not change even if the enclosing cell size changes. |
void |
setRowMargins(int side,
int value,
int... rows)
Sets the width of the margins (empty space ) at the beginning or end of the specified rows. |
void |
update()
|
void |
xmlserialize(XMLPrintStream out,
ComponentXMLSerializer c)
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final Cell NULLCELL
protected Cell[][] elements
protected byte[][] vspan
protected byte[][] hspan
protected boolean[][] draw
protected int[] colWidths
protected int[] rowHeights
public static final int NULL
public static final int HSPAN
public static final int VSPAN
public static final int DRAW
public static final Cell VSPANCELL
public static final Cell HSPANCELL
public static final java.awt.Component HSPANComponent
public static final java.awt.Component VSPANComponent
Constructor Detail |
---|
protected CellGrid(Cell[][] elements, int m, int n)
Method Detail |
---|
public void initCellGrid(Cell[][] elements, int m, int n)
public void update()
public void addComponentsToContainer(java.awt.Container container)
addComponentsToContainer
method of each cell within the grid to add the components of the cells
to the container.
addComponentsToContainer
in class Cell
container
- the container to which the components of the cells need to added.protected void setBounds(int x, int y, int width, int height)
setBounds
in class Cell
x
- the x-coordinate of the top left of the rectangle.y
- the y-coordinate of the top left of the rectangle.width
- the width of the rectangle.height
- the height of the rectangle.public void setAlignments(int[][] halign, int[][] valign)
halign
- the two-dimensional array of desired horizontal
alignments. If number of rows in this array is the less
than the number
of rows in the grid, the alignments of the last specified
array are copied to the alignments of the rest of the rows.
If the number of columns in the array is less than the number of
columns of the grid, no alignments are specified for
the remaining columns.valign
- two-dimensional array of desired vertical
alignments. If number of rows in this array is the less
of rows in the grid, the alignments of the last specified
array are copied to the alignments of the rest of the rows.
If the number of columns in the array is less than the number of
columns of the grid, no alignments are specified for
the remaining columns.public void setAlignment(int rowIndex, int columnIndex, int halign, int valign)
rowIndex
- the row index of the cell whose alignment is specified.columnIndex
- the column index of the cell whose alignment is specified.halign
- horizontal alignmentvalign
- vertical alignmentpublic static CellGrid createCellGrid(GridRow... rows)
GridRow
objects.
rows
- the array of GridRow
objects
from which to create the grid.public static CellGrid createCellGrid(java.awt.Component[][] cellArray)
Creates a CellGrid
from a two dimensional array of
components.
Not every element of the input array need contain a component.
If an element is null
, a gap is automatically created.
If an element cellArray[i][j]
is set to
CellGrid.HSPANComponent
the component
cellArray[i][j-1]
is spanned across the row to this
element.
In this fashion a component may be placed to extend to more than one element along a row.
If an element cellArray[i][j]
is set to
CellGrid.VSPANComponent
the component
cellArray[i-1][j]
is spanned across the column to this
element.
In this fashion a component may be placed to extend to more than one element along a column.
cellArray
- the two-dimensional array of components.
CellGrid
object constucted from the input array.public static CellGrid createCellGrid(Cell[][] cellArray)
Creates a CellGrid
from a two dimensional array of cells.
Not every element of the input array need contain a cell.
If an element is null
, a gap is automatically created.
If an element cellArray[i][j]
is set to
CellGrid.HSPANCELL
the cell
cellArray[i][j-1]
is spanned across the row to this
element.
In this fashion a cell may be placed to extend to more than one element along a row.
If an element cellArray[i][j]
is set to
CellGrid.VSPANCELL
the cell
cellArray[i-1][j]
is spanned across the column to this
element.
In this fashion a cell may be placed to extend to more than one element along a column.
cellArray
- the two-dimensional array of cells.
CellGrid
object constucted from the input array.public static CellGrid createCellGrid(Cell[] cellArray, int[] rowIndices, int[] colIndices)
CellGrid
from a one dimensional array of cells.
The row and column indices of the elements of each of the
cells within the grid are specified separately. Thus, for example,
if rowIndices[2]
and colIndices[2]
are
both zero, the the cell object cellArray[2]
is placed
in the top left corner of the grid. This method is convenient
if a large number of elements of the grid do not contain any cells.
The element of the grid whose indices are not referenced by any
elements of rowIndices
and colIndices
arrays are filled with gaps.
cellArray
- the one-dimensional array of cells.rowIndices
- an array of the same of same size as the first argument containing the row indices.colIndices
- an array of the same of same size as the first argument containing the column indices.
CellGrid
object constucted from the input array.public BoundSpring computeBoundSpring()
computeBoundSpring
in class Cell
public void setFixedColumnWidth(int[] columns)
columns
- the array of indices of columns whose width should be fixed.public void setFixedRowHeight(int[] rows)
rows
- the array of indices of rows whose height should be fixed.public int numberOfChildren()
numberOfChildren
in class Cell
public int numberOfRows()
public int numberOfColumns()
public Cell getCell(int rowIndex, int columnIndex)
rowIndex
- the rowIndex of the cell to be retrieved.columnIndex
- the columnIndex of the cell to be retrieved.
public Cell getChildAt(int index)
0
represents the cell on the top left corner, the index
1
represents the cell on the second column of the top row, etc., with the index wrapping around to the second row at the end the top row.
getChildAt
in class Cell
index
- the linear index of the cell to be returned.
public boolean replaceChild(int index, Cell newCell, java.awt.Container parent)
replaceChild
in class Cell
index
- the linear index of the cell to be replaced.newCell
- the cell that replaces the current cell at the specified index.parent
- the container in which the components of the cells are placed.
true
if the replacement was successful, otherwise false
.public int getIndex(int rowIndex, int columnIndex)
public void setRowMargins(int side, int value, int... rows)
side
- Cell.LEFT for specifying left margin, Cell.RIGHT for the
right margin.value
- the width of the margin.rows
- the list of indices of the rows whose margins
are to be set.public void setColumnMargins(int side, int value, int... columns)
side
- Cell.TOP for specifying top margin, Cell.BOTTOM for the
bottom margin.value
- the height of the margin.columns
- the list of indices of the columns whose margins
are to be set.protected static CellGrid createCellGrid(Cell... cells)
protected static CellGrid createCellGrid(java.lang.Object... o)
public int[] getColWidths()
public int[] getRowHeights()
public Cell duplicate(ComponentDuplicator c)
duplicate
in class Cell
public int getAlignment(int i, int j, int coord, int defaultValue)
public void xmlserialize(XMLPrintStream out, ComponentXMLSerializer c)
xmlserialize
in class Cell
public int[][][] getAlignments()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |