org.zaval.lw
Class LwGridLayout

java.lang.Object
  |
  +--org.zaval.lw.LwGridLayout
All Implemented Interfaces:
LwLayout, PosInfo

public class LwGridLayout
extends java.lang.Object
implements LwLayout, PosInfo

This class implements layout manager interface. The layout manager divides the container area into certain quantity of virtual rows and columns and every cell is used to place a child component. A column preferred width is calculated as maximal preferred width among all cells of the column. A row preferred height is calculated as maximal preferred height among all cells of the row.

If the virtual cell space is larger than the component preferred size than the additional constraints can be defined. Use LwConstraints class as the input argument of add container method to describe the cell constraints. Using the constraints you can define vertical and horizontal alignments, insets, filling rules. The table below illustrates the layout manager usage (the samples use grid layout manager with two columns and two rows): Additionally you can use stretching mask that says if the virtual cells should be stretched according to the target container size vertically or horizontally.
Constraints Sample App
Default constraints (fill=LwToolkit.HORIZONTAL|LwToolkit.VERTICAL).
Cell[1][1] uses fill=LwToolkit.HORIZONTAL, vertical alignment is LwToolkit.CENTER.
Cell[1][1] uses fill=LwToolkit.NONE, vertical alignment is Alignment.CENTER and horizontal alignment is Alignment.CENTER.
Cell[1][1] uses fill=LwToolkit.NONE, vertical alignment is Alignment.TOP and horizontal alignment is Alignment.LEFT.
Cell[1][1] uses fill=LwToolkit.VERTICAL, horizontal alignment is Alignment.RIGHT.


Constructor Summary
LwGridLayout(int r, int c)
          Constructs a new grid layout with the specified number of rows and columns.
LwGridLayout(int r, int c, int m)
          Constructs a new grid layout with the specified number of rows, columns and the layout stretching mask.
 
Method Summary
 java.awt.Dimension calcPreferredSize(LayoutContainer c)
          Calculates the preferred size dimension for the layout container.
 void componentAdded(java.lang.Object id, Layoutable b, int index)
          Invoked when the specified layoutable component is added to the layout container, that uses the layout manager.
 void componentRemoved(Layoutable lw, int index)
          Invoked when the specified layoutable component is removed from the layout container, that uses the layout manager.
 int getLines()
          Implements org.zaval.misc.PosInfo interface method to define number of lines.
 int getLineSize(int line)
          Implements org.zaval.misc.PosInfo interface method to define the line size.
 int getMaxOffset()
          Implements org.zaval.misc.PosInfo interface method to define max offset.
 void layout(LayoutContainer c)
          Lays out the child layoutable components inside the layout container.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LwGridLayout

public LwGridLayout(int r,
                    int c)
Constructs a new grid layout with the specified number of rows and columns.
Parameters:
r - the specified number of rows.
c - the specified number of columns.

LwGridLayout

public LwGridLayout(int r,
                    int c,
                    int m)
Constructs a new grid layout with the specified number of rows, columns and the layout stretching mask.
Parameters:
r - the specified number of rows.
c - the specified number of columns.
m - the layout stretching mask. The mask indicates if it is necessary to stretch virtual cells' sizes according to a parent area size. Use LwToolkit.HORIZONTAL, LwToolkit.VERTICAL or LwToolkit.NONE values to construct the mask value.
Method Detail

calcPreferredSize

public java.awt.Dimension calcPreferredSize(LayoutContainer c)
Calculates the preferred size dimension for the layout container. The method calculates "pure" preferred size, it means that an insets of the container is not considered.
Specified by:
calcPreferredSize in interface LwLayout
Parameters:
c - the layout container.

layout

public void layout(LayoutContainer c)
Lays out the child layoutable components inside the layout container.
Specified by:
layout in interface LwLayout
Parameters:
c - the layout container that needs to be laid out.

componentAdded

public void componentAdded(java.lang.Object id,
                           Layoutable b,
                           int index)
Invoked when the specified layoutable component is added to the layout container, that uses the layout manager. The specified constraints, layoutable component and child index are passed as arguments into the method. The method stores the specified constraints for the component if the constraints are defined.
Specified by:
componentAdded in interface LwLayout
Parameters:
id - the layoutable component constraints.
b - the layoutable component.
index - the child index.

componentRemoved

public void componentRemoved(Layoutable lw,
                             int index)
Invoked when the specified layoutable component is removed from the layout container, that uses the layout manager. The manager removes appropriate constraints for the given component if the constraints have been defined.
Specified by:
componentRemoved in interface LwLayout
Parameters:
lw - the layoutable component to be removed
index - the child index.

getLines

public int getLines()
Implements org.zaval.misc.PosInfo interface method to define number of lines. The implementation provides ability to navigate over the layout manager owner components using org.zaval.misc.PosController class.
Specified by:
getLines in interface PosInfo
Returns:
a number of lines. The method returns number of rows as the number of lines.

getLineSize

public int getLineSize(int line)
Implements org.zaval.misc.PosInfo interface method to define the line size. The implementation provides ability to navigate over the layout manager owner components using org.zaval.misc.PosController class.
Specified by:
getLineSize in interface PosInfo
Parameters:
line - the line number.
Returns:
a size of the specified line. The method returns number of columns as the size for any line number.

getMaxOffset

public int getMaxOffset()
Implements org.zaval.misc.PosInfo interface method to define max offset. The implementation provides ability to navigate over the layout manager owner components using org.zaval.misc.PosController class.
Specified by:
getMaxOffset in interface PosInfo
Returns:
a max offset. The max offset is computed as "(rows * columns - 1)" value.


Copyright © Zaval Creative Engineering Group, 2000-2005.
http://www.zaval.org