org.tigris.swidgets
Class GridLayout2

java.lang.Object
  extended byorg.tigris.swidgets.GridLayout2
All Implemented Interfaces:
java.awt.LayoutManager, java.io.Serializable
Direct Known Subclasses:
NewspaperLayout

public class GridLayout2
extends java.lang.Object
implements java.awt.LayoutManager, java.io.Serializable

Same as the standard java class GridLayout but allows more flexability for sizing of columns and rows.

See Also:
Serialized Form

Field Summary
static int BOTH
          Resize all child components to fit their cell both horizontally and vertically.
static int CENTER
          Put the component in the center of its display area.
static int EAST
          Put the component on the right side of its display area, centered vertically.
static int FITPARENT
          Size all cells as the same width and height to fit the parent component.
static int HORIZONTAL
          Resize all child components to fit their cell horizontally but not vertically.
static int MAXPREFERRED
          Size all cells as the largest prefered width and height component.
static int NONE
          Do not resize the child components.
static int NORTH
          Put the component at the top of its display area, centered horizontally.
static int NORTHEAST
          Put the component at the top-right corner of its display area.
static int NORTHWEST
          Put each component in the top-left corner of its display area.
static int ROWCOLPREFERRED
          Size all cells so that all in the same row are the same height and all in the same column are the same width.
static int SOUTH
          Put the component at the bottom of its display area, centered horizontally.
static int SOUTHEAST
          Put the component at the bottom-right corner of its display area.
static int SOUTHWEST
          Put the component at the bottom-left corner of its display area.
static int VERTICAL
          Resize all child components to fit their cell vertically but not horizontally.
static int WEST
          Put the component on the left side of its display area, centered vertically.
 
Constructor Summary
GridLayout2()
          Construct a new GridLayout2 with a default of one column per component, in a single row.
GridLayout2(int r, int c)
          Construct a new GridLayout2 with the specified number of rows and columns.
GridLayout2(int r, int c, int cs)
          Construct a new GridLayout2 with the specified number of rows and columns and cell sizing scheme.
GridLayout2(int r, int c, int h, int v)
          Construct a new GridLayout2 with the specified number of rows and columns and cell spacing.
GridLayout2(int r, int c, int h, int v, int cs)
          Construct a new GridLayout2 with the specified number of rows and columns, cell spacing and cell sizing scheme.
GridLayout2(int r, int c, int h, int v, int cs, int f)
          Construct a new GridLayout2 with the specified number of rows and columns, cell spacing, cell sizing scheme and filling scheme.
GridLayout2(int r, int c, int h, int v, int cs, int f, int a)
          Construct a new GridLayout2 with the specified number of rows and columns, cell spacing, cell sizing scheme and component sizing and anchoring scheme.
 
Method Summary
 void addLayoutComponent(java.lang.String name, java.awt.Component comp)
          Adds the specified component with the specified name to the layout.
protected  java.awt.Dimension calculateSizes(java.awt.Container parent, int[] theColWidth, int[] theRowHeight, int actualRows, int actualCols, int theLargestWidth, int theLargestHeight)
          Calculate the layout size.
 int getColumns()
           
protected  int[] getColWidth()
           
protected  int getComponentCellHeight(int row)
          Calculate the cell height.
protected  int getComponentCellWidth(int col)
          Calculate the cell width.
 int getHgap()
           
protected  int getLargestHeight()
           
protected  int getLargestWidth()
           
protected  int[] getRowHeight()
           
 int getRows()
           
 int getVgap()
           
 void layoutContainer(java.awt.Container parent)
           
 java.awt.Dimension minimumLayoutSize(java.awt.Container parent)
          Required by LayoutManager.
protected  void positionComponentInCell(java.awt.Component comp, int x, int y, int cellWidth, int cellHeight)
           
 java.awt.Dimension preferredLayoutSize(java.awt.Container parent)
          Determines the preferred size of the container argument using this grid layout.
 void removeLayoutComponent(java.awt.Component comp)
          Removes the specified component with the specified name from the layout.
 void setCols(int c)
           
protected  void setColWidth(int[] cw)
           
 void setHgap(int h)
           
protected  void setLargestHeight(int lh)
           
protected  void setLargestWidth(int lw)
           
protected  void setRowHeight(int[] rh)
           
 void setRows(int r)
           
 void setVgap(int v)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NONE

public static final int NONE
Do not resize the child components.

See Also:
Constant Field Values

BOTH

public static final int BOTH
Resize all child components to fit their cell both horizontally and vertically.

See Also:
Constant Field Values

HORIZONTAL

public static final int HORIZONTAL
Resize all child components to fit their cell horizontally but not vertically.

See Also:
Constant Field Values

VERTICAL

public static final int VERTICAL
Resize all child components to fit their cell vertically but not horizontally.

See Also:
Constant Field Values

CENTER

public static final int CENTER
Put the component in the center of its display area.

See Also:
Constant Field Values

NORTH

public static final int NORTH
Put the component at the top of its display area, centered horizontally.

See Also:
Constant Field Values

NORTHEAST

public static final int NORTHEAST
Put the component at the top-right corner of its display area.

See Also:
Constant Field Values

EAST

public static final int EAST
Put the component on the right side of its display area, centered vertically.

See Also:
Constant Field Values

SOUTHEAST

public static final int SOUTHEAST
Put the component at the bottom-right corner of its display area.

See Also:
Constant Field Values

SOUTH

public static final int SOUTH
Put the component at the bottom of its display area, centered horizontally.

See Also:
Constant Field Values

SOUTHWEST

public static final int SOUTHWEST
Put the component at the bottom-left corner of its display area.

See Also:
Constant Field Values

WEST

public static final int WEST
Put the component on the left side of its display area, centered vertically.

See Also:
Constant Field Values

NORTHWEST

public static final int NORTHWEST
Put each component in the top-left corner of its display area.

See Also:
Constant Field Values

MAXPREFERRED

public static final int MAXPREFERRED
Size all cells as the largest prefered width and height component.

A possible value for the cellSizing parameter of the constructor in order to size cells so that each have the same width and height. The width is the largest prefered width and the height is the largest prefered height of all these child components.

See Also:
Constant Field Values

ROWCOLPREFERRED

public static final int ROWCOLPREFERRED
Size all cells so that all in the same row are the same height and all in the same column are the same width.

A possible value for the cellSizing parameter of the constructor. The width is the largest prefered width of all components in the same column and the height is the largest prefered height of all components in the same row.

See Also:
Constant Field Values

FITPARENT

public static final int FITPARENT
Size all cells as the same width and height to fit the parent component.

A possible value for the cellSizing parameter of the constructor in order to size cells so that each has the same height and width and are sized to fit their parent. This emulates the sizing done by a standard GridLayout.

See Also:
Constant Field Values
Constructor Detail

GridLayout2

public GridLayout2()
Construct a new GridLayout2 with a default of one column per component, in a single row.


GridLayout2

public GridLayout2(int r,
                   int c)
Construct a new GridLayout2 with the specified number of rows and columns.

Parameters:
r - the number of rows in the layout
c - the number of columns in the layout

GridLayout2

public GridLayout2(int r,
                   int c,
                   int h,
                   int v)
Construct a new GridLayout2 with the specified number of rows and columns and cell spacing.

Parameters:
r - the number of rows in the layout
c - the number of columns in the layout
h - the horizontal gap between cells
v - the vertical gap between cells

GridLayout2

public GridLayout2(int r,
                   int c,
                   int cs)
Construct a new GridLayout2 with the specified number of rows and columns and cell sizing scheme.

Parameters:
r - the number of rows in the layout
c - the number of columns in the layout
cs - the required cell sizing scheme

GridLayout2

public GridLayout2(int r,
                   int c,
                   int h,
                   int v,
                   int cs)
Construct a new GridLayout2 with the specified number of rows and columns, cell spacing and cell sizing scheme.

Parameters:
r - the number of rows in the layout
c - the number of columns in the layout
h - the horizontal gap between cells
v - the vertical gap between cells
cs - the required cell sizing scheme

GridLayout2

public GridLayout2(int r,
                   int c,
                   int h,
                   int v,
                   int cs,
                   int f)
Construct a new GridLayout2 with the specified number of rows and columns, cell spacing, cell sizing scheme and filling scheme.

Parameters:
r - the number of rows in the layout
c - the number of columns in the layout
h - the horizontal gap between cells
v - the vertical gap between cells
cs - the required cell sizing scheme
f - the required cell filling scheme

GridLayout2

public GridLayout2(int r,
                   int c,
                   int h,
                   int v,
                   int cs,
                   int f,
                   int a)
Construct a new GridLayout2 with the specified number of rows and columns, cell spacing, cell sizing scheme and component sizing and anchoring scheme.

Parameters:
r - the number of rows in the layout
c - the number of columns in the layout
h - the horizontal gap between cells
v - the vertical gap between cells
cs - the required cell sizing scheme
f - the required cell filling scheme
a - the required anchoring of a child component within its cell
Method Detail

addLayoutComponent

public void addLayoutComponent(java.lang.String name,
                               java.awt.Component comp)
Adds the specified component with the specified name to the layout. This is included to satisfy the LayoutManager interface but is not actually used in this layout implementation.

Specified by:
addLayoutComponent in interface java.awt.LayoutManager
Parameters:
name - the name of the component
comp - the component to be added

removeLayoutComponent

public void removeLayoutComponent(java.awt.Component comp)
Removes the specified component with the specified name from the layout. This is included to satisfy the LayoutManager interface but is not actually used in this layout implementation.

Specified by:
removeLayoutComponent in interface java.awt.LayoutManager
Parameters:
comp - the name of the component

preferredLayoutSize

public java.awt.Dimension preferredLayoutSize(java.awt.Container parent)
Determines the preferred size of the container argument using this grid layout. The preferred size of a grid layout is dependant on the cellSizing scheme.

MAXPREFERRED and FITPARENT use the same formula to calculate prefered size.

The prefered width using MAXPREFERRED or FITPARENT is the largest preferred width of any of the widths in the container times the number of columns, plus the horizontal padding times the number of columns plus one, plus the left and right insets of the target container.

The preferred height using MAXPREFERRED or FITPARENT is the largest preferred height of any of the heights in the container times the number of rows, plus the vertical padding times the number of rows plus one, plus the top and bottom insets of the target container.

The prefered width using ROWCOLPREFERRED is the largest preferred is the sum of the widths of of all columns, plus the horizontal padding times the number of columns plus one, plus the left and right insets of the target container.

The prefered height using ROWCOLPREFERRED is the largest preferred is the sum of the heights of of all columns, plus the horizontal padding times the number of columns plus one, plus the left and right insets of the target container.

Specified by:
preferredLayoutSize in interface java.awt.LayoutManager
Parameters:
parent - the container to be laid out
Returns:
the preferred dimensions to lay out the subcomponents of the specified container

minimumLayoutSize

public java.awt.Dimension minimumLayoutSize(java.awt.Container parent)
Required by LayoutManager.

Specified by:
minimumLayoutSize in interface java.awt.LayoutManager
See Also:
LayoutManager.minimumLayoutSize(java.awt.Container)

layoutContainer

public void layoutContainer(java.awt.Container parent)
Specified by:
layoutContainer in interface java.awt.LayoutManager
See Also:
LayoutManager.layoutContainer(java.awt.Container)

calculateSizes

protected java.awt.Dimension calculateSizes(java.awt.Container parent,
                                            int[] theColWidth,
                                            int[] theRowHeight,
                                            int actualRows,
                                            int actualCols,
                                            int theLargestWidth,
                                            int theLargestHeight)
Calculate the layout size.

Parameters:
parent - the container
theColWidth - the column width
theRowHeight - the row height
actualRows - the number of rows specified for the grid. This should be a non negative integer, where '0' means 'any number' meaning that the number of rows in that dimension depends on the other dimension.
actualCols - the number of columns specified for the grid. This should be a non negative integer, where '0' means 'any number' meaning that the number of columns in that dimension depends on the other dimension.
theLargestWidth - the largest width
theLargestHeight - the largest height
Returns:
the dimension of the layout

getComponentCellHeight

protected int getComponentCellHeight(int row)
Calculate the cell height.

Parameters:
row - the row for this cell
Returns:
the height

getComponentCellWidth

protected int getComponentCellWidth(int col)
Calculate the cell width.

Parameters:
col - the column of this cell
Returns:
the width

positionComponentInCell

protected void positionComponentInCell(java.awt.Component comp,
                                       int x,
                                       int y,
                                       int cellWidth,
                                       int cellHeight)
Parameters:
comp - the component to be positioned
x - the x
y - the y
cellWidth - the width of the cell
cellHeight - the height of the cell

getRows

public int getRows()
Returns:
the number of rows

setRows

public void setRows(int r)
Parameters:
r - the number of rows. It can not be zero.

getColumns

public int getColumns()
Returns:
the number of columns

setCols

public void setCols(int c)
Parameters:
c - the number of columns. It can not be zero.

getHgap

public int getHgap()
Returns:
the horizontal gap

setHgap

public void setHgap(int h)
Parameters:
h - the horizontal gap

getVgap

public int getVgap()
Returns:
the vertical gap

setVgap

public void setVgap(int v)
Parameters:
v - the vertical gap

setLargestHeight

protected void setLargestHeight(int lh)
Parameters:
lh - The largestHeight to set.

getLargestHeight

protected int getLargestHeight()
Returns:
Returns the largestHeight.

setLargestWidth

protected void setLargestWidth(int lw)
Parameters:
lw - The largestWidth to set.

getLargestWidth

protected int getLargestWidth()
Returns:
Returns the largestWidth.

setColWidth

protected void setColWidth(int[] cw)
Parameters:
cw - The colWidth to set.

getColWidth

protected int[] getColWidth()
Returns:
Returns the colWidth.

setRowHeight

protected void setRowHeight(int[] rh)
Parameters:
rh - The rowHeight to set.

getRowHeight

protected int[] getRowHeight()
Returns:
Returns the rowHeight.