EchoPoint
1.0

echopoint.layout
Class GridLayoutManager

java.lang.Object
  extended byechopoint.layout.AbstractLayoutManager
      extended byechopoint.layout.GridLayoutManager
All Implemented Interfaces:
LayoutManager, java.io.Serializable

public class GridLayoutManager
extends AbstractLayoutManager

The GridLayoutManager allows Components to be laid out using a grid patterm. It maintains a current "cursor" {col,row} to allow Components to be easily added and it also maintains a width and height.

The simplest way to use this class is to add Components without CellConstraints objects. This will add them in order (using the cursor) expanding the height of the grid as necessary. If a Component is already in a cell, then the cursor will be moved to the next empty cell and the component will be placed there.

If you want, CellConstraints objects can be used to allow Components to be placed at specific positions or to span a number of columns or rows. When these constraints are used, they must fit within the current grid dimensions or an OutOfBoundsException will be thrown. The grid is never "auto-expanded" when using CellConstraints objects.

You must also ensure that the CellConstraints objects do not overlap otherwise an OverlapException will be thrown

If a row has no components in it, for example newLine() is called in the first column, then nothing will be rendered in that row.

See Also:
Serialized Form

Nested Class Summary
static class GridLayoutManager.CellConstraints
          This class is designed to be used as a contraints object with GridLayoutManager.
 class GridLayoutManager.OutOfBoundsException
          An OutOfBoundsException exception is thrown if any of the CellConstraints constaints are outside the width or height of the GridLayoutManager.
 class GridLayoutManager.OverlapException
          An OverlapException exception is thrown if any of the CellConstraints constaints overlap.
 
Field Summary
static int EVEN_CENTER
          Can be OR'ed onto an alignment value to make even columns align center
static int EVEN_LEFT
          Can be OR'ed onto an alignment value to make even columns align left
static int EVEN_RIGHT
          Can be OR'ed onto an alignment value to make even columns align right
static int HORZ_ALIGNMENT_MASK
          a bit mask that removes the ODD/EVEN alignment values
static int ODD_CENTER
          Can be OR'ed onto an alignment value to make odd columns align center
static int ODD_LEFT
          Can be OR'ed onto an alignment value to make odd columns align left
static int ODD_RIGHT
          Can be OR'ed onto an alignment value to make odd columns align right
 
Fields inherited from class echopoint.layout.AbstractLayoutManager
componentMap, layoutManageableWR
 
Constructor Summary
GridLayoutManager()
          Constructs a GridLayoutManager that is define as 1 x 1000.
GridLayoutManager(int width, int height)
          Constructs a GridLayoutManager with the specified width and height.
 
Method Summary
 void addLayoutComponent(nextapp.echo.Component comp)
          Adds a component to the LayoutManager in the next available cell.
 void addLayoutComponent(nextapp.echo.Component comp, java.lang.Object constraints)
          Adds a component to the LayoutManager with the specified contraints object.
 int getCellSpacing()
          Gets the cellspacing of the GridLayoutManager
 nextapp.echo.Component getComponent(int col, int row)
          This returns the Component currently at position {col,row} or null if no component is currently there.
 GridLayoutManager.CellConstraints getContraints(int col, int row)
          This returns the GridCellConstraint currently at position {col,row} or null if no component is currently there.
 int getCursorColumn()
          Returns the current Column position of the Grid cursor.
 int getCursorRow()
          Returns the current Row position of the Grid cursor
 int getHeight()
          Gets the height of the GridLayoutManager
 int getHorizontalAlignment()
          Gets the horizontal alignment of the GridLayoutManager.
 int getVerticalAlignment()
          Gets the vertical alignment of the GridLayoutManager.
 int getWidth()
          Sets the height of the GridLayoutManager
 boolean isFullHeight()
          Returns TRUE if the GridLayoutManager will fill its parents full height
 boolean isFullWidth()
          Returns TRUE if the GridLayoutManager will fill its parents full width
 void newLine()
          Moves the current cursor position down a row and to the first column (col == 0) in the grid.
 void removeLayoutComponent(nextapp.echo.Component comp)
          Removes a component from the LayoutManager.
 void removeLayoutComponent(int col, int row)
          Removes a component from the GridLayoutManager at the specified position.
 void setCellSpacing(int newCellSpacing)
          Sets the cell spacing of the GridLayoutManager
 void setCursorColumn(int newColumn)
          Sets the current Column position of the Grid cursor.
 void setCursorRow(int newRow)
          Sets the current Row position of the Grid cursor
 void setFullHeight(boolean newFullHeight)
          If this is TRUE then the GridLayoutManager will fill its parents full height.
 void setFullWidth(boolean newFullWidth)
          If this is TRUE then the GridLayoutManager will fill its parents full width.
 void setHeight(int newHeight)
          Sets the height of the GridLayoutManager.
 void setHorizontalAlignment(int newHorizontalAlignment)
          Sets the horizontal alignment of the GridLayoutManager.
 void setVerticalAlignment(int newVerticalAlignment)
          Sets the vertical alignment of the GridLayoutManager.
 void setWidth(int newWidth)
          Sets the width of the GridLayoutManager.
 void space()
          Moves the current cursor position along one column.
 java.lang.String toString()
           
 
Methods inherited from class echopoint.layout.AbstractLayoutManager
getComponent, getComponentMap, getContraints, getLayoutManageable, invalidateLayout, setLayoutManageable
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

ODD_LEFT

public static final int ODD_LEFT
Can be OR'ed onto an alignment value to make odd columns align left

See Also:
Constant Field Values

ODD_RIGHT

public static final int ODD_RIGHT
Can be OR'ed onto an alignment value to make odd columns align right

See Also:
Constant Field Values

ODD_CENTER

public static final int ODD_CENTER
Can be OR'ed onto an alignment value to make odd columns align center

See Also:
Constant Field Values

EVEN_LEFT

public static final int EVEN_LEFT
Can be OR'ed onto an alignment value to make even columns align left

See Also:
Constant Field Values

EVEN_RIGHT

public static final int EVEN_RIGHT
Can be OR'ed onto an alignment value to make even columns align right

See Also:
Constant Field Values

EVEN_CENTER

public static final int EVEN_CENTER
Can be OR'ed onto an alignment value to make even columns align center

See Also:
Constant Field Values

HORZ_ALIGNMENT_MASK

public static final int HORZ_ALIGNMENT_MASK
a bit mask that removes the ODD/EVEN alignment values

See Also:
Constant Field Values
Constructor Detail

GridLayoutManager

public GridLayoutManager()
Constructs a GridLayoutManager that is define as 1 x 1000.

Therefore If you add Components to this grid without specifying the co-ordinates, then the Components will line up left to right until you call GridLayoutManager.newLine();


GridLayoutManager

public GridLayoutManager(int width,
                         int height)
Constructs a GridLayoutManager with the specified width and height. Components added to this grid without specific contraints will wrap when the cursor reaches the specified width.

Method Detail

addLayoutComponent

public void addLayoutComponent(nextapp.echo.Component comp)
                        throws GridLayoutManager.OutOfBoundsException,
                               GridLayoutManager.OverlapException
Adds a component to the LayoutManager in the next available cell.

The Component will be added at the current cursor position. If the cell at the current cursor position has a Component it it, the new Component will added at the next available cell, extending the grid down as required.

Also note that the cursor is moved to the next logical position for adding a new Component.

This method is not intended to be called by any other than an LayoutManageable during Component add().

Throws:
GridLayoutManager.OutOfBoundsException
GridLayoutManager.OverlapException

addLayoutComponent

public void addLayoutComponent(nextapp.echo.Component comp,
                               java.lang.Object constraints)
                        throws GridLayoutManager.OutOfBoundsException,
                               GridLayoutManager.OverlapException
Adds a component to the LayoutManager with the specified contraints object. The contraints object must be an instance of GridCellArea or null. If the contraints Object is null then tyhis method acts in the same way as the addLayoutComponent(Component comp) method does.

This method is not intended to be called by any other than an LayoutManageable during Component add().

Specified by:
addLayoutComponent in interface LayoutManager
Overrides:
addLayoutComponent in class AbstractLayoutManager
Throws:
GridLayoutManager.OutOfBoundsException
GridLayoutManager.OverlapException

getCellSpacing

public int getCellSpacing()
Gets the cellspacing of the GridLayoutManager

Returns:
int - the cellspacing of the GridLayoutManager

getComponent

public nextapp.echo.Component getComponent(int col,
                                           int row)
This returns the Component currently at position {col,row} or null if no component is currently there.


getContraints

public GridLayoutManager.CellConstraints getContraints(int col,
                                                       int row)
This returns the GridCellConstraint currently at position {col,row} or null if no component is currently there.


getCursorColumn

public int getCursorColumn()
Returns the current Column position of the Grid cursor.

Returns:
int

getCursorRow

public int getCursorRow()
Returns the current Row position of the Grid cursor

Returns:
int

getHeight

public int getHeight()
Gets the height of the GridLayoutManager

Returns:
int

getHorizontalAlignment

public int getHorizontalAlignment()
Gets the horizontal alignment of the GridLayoutManager.

This can be one of the EchoConstant values :

You can also "OR" on the following values to overrride the above

The above will only be applied to their respective "odd" or "even" columns.

Returns:
int

getVerticalAlignment

public int getVerticalAlignment()
Gets the vertical alignment of the GridLayoutManager.

This can be one of the EchoConstant values :

Returns:
int

getWidth

public int getWidth()
Sets the height of the GridLayoutManager

Returns:
int

isFullHeight

public boolean isFullHeight()
Returns TRUE if the GridLayoutManager will fill its parents full height

Returns:
boolean

isFullWidth

public boolean isFullWidth()
Returns TRUE if the GridLayoutManager will fill its parents full width

Returns:
boolean

newLine

public void newLine()
Moves the current cursor position down a row and to the first column (col == 0) in the grid. The height will be expanded to accomodate this change.


removeLayoutComponent

public void removeLayoutComponent(int col,
                                  int row)
Removes a component from the GridLayoutManager at the specified position.


removeLayoutComponent

public void removeLayoutComponent(nextapp.echo.Component comp)
Removes a component from the LayoutManager. This method is called by the containing component when a child component is to be removed.

Specified by:
removeLayoutComponent in interface LayoutManager
Overrides:
removeLayoutComponent in class AbstractLayoutManager

setCellSpacing

public void setCellSpacing(int newCellSpacing)
Sets the cell spacing of the GridLayoutManager

Parameters:
newCellSpacing - int

setCursorColumn

public void setCursorColumn(int newColumn)
Sets the current Column position of the Grid cursor.


setCursorRow

public void setCursorRow(int newRow)
Sets the current Row position of the Grid cursor


setFullHeight

public void setFullHeight(boolean newFullHeight)
If this is TRUE then the GridLayoutManager will fill its parents full height.

Parameters:
newFullHeight - boolean

setFullWidth

public void setFullWidth(boolean newFullWidth)
If this is TRUE then the GridLayoutManager will fill its parents full width.

Parameters:
newFullWidth - boolean

setHeight

public void setHeight(int newHeight)
               throws GridLayoutManager.OutOfBoundsException
Sets the height of the GridLayoutManager. This will throws an OutOfBoundsException if the newHeight is less than current constraints.

Parameters:
newHeight - int
Throws:
GridLayoutManager.OutOfBoundsException

setHorizontalAlignment

public void setHorizontalAlignment(int newHorizontalAlignment)
Sets the horizontal alignment of the GridLayoutManager.

This can be one of the EchoConstant values :

You can also "OR" on the following values to overrride the above

The above will only be applied to their respective "odd" or "even" columns.

Parameters:
newHorizontalAlignment - int

setVerticalAlignment

public void setVerticalAlignment(int newVerticalAlignment)
Sets the vertical alignment of the GridLayoutManager.

This can be one of the EchoConstant values :

Parameters:
newVerticalAlignment - int

setWidth

public void setWidth(int newWidth)
              throws GridLayoutManager.OutOfBoundsException
Sets the width of the GridLayoutManager. This will throws an OutOfBoundsException if the newWidth is less than current constraints.

Parameters:
newWidth - int
Throws:
GridLayoutManager.OutOfBoundsException

space

public void space()
Moves the current cursor position along one column. If this moves the cursor position past the width of the grid, then the cursor will be moved down a row and set to the first column.


toString

public java.lang.String toString()
See Also:
Object.toString()

EchoPoint
1.0