pagelayout
Class CellGrid

java.lang.Object
  extended by pagelayout.Cell
      extended by pagelayout.CellGrid

public class CellGrid
extends Cell

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.

A number of methods are available to modify the layout of the grid once it has been constructed.

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.

See Also:
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 pagelayout.Cell
addArgs, alignBaseline, alignBaseline, checkArgs, createLayout, dupConstraint, getAlignment, getBaseline, getBoundSpring, getCellByName, getComponent, getComponentCell, getComponentCell, getConstraint, getContainer, getDim, getFilledSizeX, getFilledSizeY, getName, getParent, getRootCell, getSize, invalidate, isCell, isCellOrComponent, isComponentCell, isFixedHeight, isFixedSize, isFixedWidth, layout, linkHeight, linkHeight, linkHeight, linkToContainerHeight, linkToContainerWidth, linkWidth, linkWidth, linkWidth, removeAllComponents, removeComponent, replaceCell, setAlignment, setBounds, setComponentGaps, setDim, setFixedHeight, setFixedHeight, setFixedHeight, setFixedHeight, setFixedHeight, setFixedSize, setFixedSize, setFixedSize, setFixedWidth, setFixedWidth, setFixedWidth, setFixedWidth, setFixedWidth, setName, setParent, setSize, setVisible
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NULLCELL

public static final Cell NULLCELL

elements

protected Cell[][] elements

vspan

protected byte[][] vspan

hspan

protected byte[][] hspan

draw

protected boolean[][] draw

colWidths

protected int[] colWidths

rowHeights

protected int[] rowHeights

NULL

public static final int NULL
See Also:
Constant Field Values

HSPAN

public static final int HSPAN
See Also:
Constant Field Values

VSPAN

public static final int VSPAN
See Also:
Constant Field Values

DRAW

public static final int DRAW
See Also:
Constant Field Values

VSPANCELL

public static final Cell VSPANCELL
Cell to be inserted in a grid of cells for vertical spanning.


HSPANCELL

public static final Cell HSPANCELL
Cell to be inserted in a grid of cells for horizontal spanning.


HSPANComponent

public static final java.awt.Component HSPANComponent
Component to be inserted in a grid of components for horizontal spanning.


VSPANComponent

public static final java.awt.Component VSPANComponent
Component to be inserted in a grid of components for vertical spanning.

Constructor Detail

CellGrid

protected CellGrid(Cell[][] elements,
                   int m,
                   int n)
Method Detail

initCellGrid

public void initCellGrid(Cell[][] elements,
                         int m,
                         int n)

update

public void update()

addComponentsToContainer

public 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.

Overrides:
addComponentsToContainer in class Cell
Parameters:
container - the container to which the components of the cells need to added.

setBounds

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.

Overrides:
setBounds in class Cell
Parameters:
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.

setAlignments

public 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.

Parameters:
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.

setAlignment

public void setAlignment(int rowIndex,
                         int columnIndex,
                         int halign,
                         int valign)
Sets the vertical and horizontal alignments of a cell in the frid.

Parameters:
rowIndex - the row index of the cell whose alignment is specified.
columnIndex - the column index of the cell whose alignment is specified.
halign - horizontal alignment
valign - vertical alignment

createCellGrid

public static CellGrid createCellGrid(GridRow... rows)
Creates grid of cells from an array of GridRow objects.

Parameters:
rows - the array of GridRow objects from which to create the grid.

createCellGrid

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.

Parameters:
cellArray - the two-dimensional array of components.
Returns:
The CellGrid object constucted from the input array.

createCellGrid

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.

Parameters:
cellArray - the two-dimensional array of cells.
Returns:
The CellGrid object constucted from the input array.

createCellGrid

public static CellGrid createCellGrid(Cell[] cellArray,
                                      int[] rowIndices,
                                      int[] colIndices)
Creates a 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.

Parameters:
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.
Returns:
The CellGrid object constucted from the input array.

computeBoundSpring

public BoundSpring computeBoundSpring()
Computes the two-dimensional spring associated with the grid that results from the approriate combination of the springs of the child cells.

Specified by:
computeBoundSpring in class Cell
Returns:
The computed two-dimensional spring.

setFixedColumnWidth

public void setFixedColumnWidth(int[] columns)
Fixes the widths of the specified columns so they do not change even if the enclosing cell size changes. Otherwise this property is determined by the properties of the child cells.

Parameters:
columns - the array of indices of columns whose width should be fixed.

setFixedRowHeight

public void setFixedRowHeight(int[] rows)
Fixes the heights of the specified rows so they do not change even if the enclosing cell size changes. Otherwise this property is determined by the properties of the child cells.

Parameters:
rows - the array of indices of rows whose height should be fixed.

numberOfChildren

public int numberOfChildren()
Returns the number of cells in the grid.

Overrides:
numberOfChildren in class Cell
Returns:
The number of (empty as well non-empty) cells in the grid.

numberOfRows

public int numberOfRows()
Returns the number of rows in the grid.

Returns:
The number of rows in the grid.

numberOfColumns

public int numberOfColumns()
Returns the number of columns in the grid.

Returns:
The number of columns in the grid.

getCell

public Cell getCell(int rowIndex,
                    int columnIndex)
Returns the cell at the given row and column indices.

Parameters:
rowIndex - the rowIndex of the cell to be retrieved.
columnIndex - the columnIndex of the cell to be retrieved.
Returns:
The cell at the given row and column indices.

getChildAt

public Cell getChildAt(int index)
Return the child cell of the grid that is associated with the given (linear) index. For this purpose the cells are indexed from row to row, i.e., the 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.

Overrides:
getChildAt in class Cell
Parameters:
index - the linear index of the cell to be returned.
Returns:
The cell associated with the given index.

replaceChild

public boolean replaceChild(int index,
                            Cell newCell,
                            java.awt.Container parent)
Replace the cell at the specified index with a new cell.

Overrides:
replaceChild in class Cell
Parameters:
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.
Returns:
true if the replacement was successful, otherwise false.

getIndex

public int getIndex(int rowIndex,
                    int columnIndex)

setRowMargins

public 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.

Parameters:
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.

setColumnMargins

public 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.

Parameters:
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.

createCellGrid

protected static CellGrid createCellGrid(Cell... cells)

createCellGrid

protected static CellGrid createCellGrid(java.lang.Object... o)

getColWidths

public int[] getColWidths()

getRowHeights

public int[] getRowHeights()

duplicate

public Cell duplicate(ComponentDuplicator c)
Specified by:
duplicate in class Cell

getAlignment

public int getAlignment(int i,
                        int j,
                        int coord,
                        int defaultValue)

xmlserialize

public void xmlserialize(XMLPrintStream out,
                         ComponentXMLSerializer c)
Specified by:
xmlserialize in class Cell

getAlignments

public int[][][] getAlignments()