jwo.utils.gui
Class SGLayout

java.lang.Object
  extended byjwo.utils.gui.SGLayout
All Implemented Interfaces:
LayoutManager, Serializable
Direct Known Subclasses:
PointLayout, SCLayout, SRLayout

public class SGLayout
extends Object
implements LayoutManager, Serializable

Creates simple scalded grid layout with multiple columns and rows. See JavaWorld Tips, 129.

Version:
2.1, 9th August, 2002
Author:
John Redmond, modified by Jo Wood
See Also:
Serialized Form

Field Summary
static int BOTTOM
          Indicates bottom alignment of a cell.
protected  int bottomBorder
           
static int CENTER
          Indicates centred alignment of a cell.
protected  int cols
           
protected  double[] columnScale
           
protected  int[] columnSizes
           
static int FILL
          Indicates cell should fill available space.
protected  int hAlignment
           
protected  int[][] hAlignments
           
protected  int hgap
           
static int LEFT
          Indicates left alignment of a cell.
protected  int leftBorder
           
protected  int minH
           
protected  int minW
           
static int RIGHT
          Indicates right alignment of a cell.
protected  int rightBorder
           
protected  int rows
           
protected  double[] rowScale
           
protected  int[] rowSizes
           
static int TOP
          Indicates top alignment of a cell.
protected  int topBorder
           
protected  int vAlignment
           
protected  int[][] vAlignments
           
protected  int vgap
           
 
Constructor Summary
SGLayout()
          Creates a default (2 x 2) layout.
SGLayout(int rows, int cols)
          Creates a layout with the specified number of rows and columns.
SGLayout(int rows, int cols, int hgap, int vgap)
          Creates a layout with the specified number of rows and columns and specified gaps.
SGLayout(int rows, int cols, int hAlignment, int vAlignment, int hgap, int vgap)
          Creates a layout with the specified number of rows and columns, specified gaps and aligment properties.
 
Method Summary
 void addLayoutComponent(String name, Component comp)
          Adds a component to the layout, but does nothing in this case.
protected  void allocateMaxSizes(Container parent)
          Update the maximum sizes for each of the grid cells using the specified scale values for rows and columns.
 void layoutContainer(Container parent)
          Lays out the specified container using this layout within the calculated grids.
 Dimension minimumLayoutSize(Container parent)
          Determines the minimum size of the container argument using this grid layout.
 Dimension preferredLayoutSize(Container parent)
          Determines the preferred size of the container argument using this grid layout.
 void removeLayoutComponent(Component comp)
          Adds a component to the layout, but does nothing in this case.
 void setAlignment(int row, int col, int hAlignment, int vAlignment)
          Set up alignment for a specific cell.
 void setColumnAlignment(int col, int hAlignment, int vAlignment)
          Set up alignment for a specific column.
 void setColumnScale(int index, double prop)
          Sets up scale value for a specific column.
 void setMargins(int topBorder, int leftBorder, int bottomBorder, int rightBorder)
          Sets up the margins for the whole layout.
 void setRowAlignment(int row, int hAlignment, int vAlignment)
          Set up alignment for a specific row.
 void setRowScale(int index, double prop)
          Sets up scale value for a specific row.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LEFT

public static final int LEFT
Indicates left alignment of a cell.

See Also:
Constant Field Values

CENTER

public static final int CENTER
Indicates centred alignment of a cell.

See Also:
Constant Field Values

RIGHT

public static final int RIGHT
Indicates right alignment of a cell.

See Also:
Constant Field Values

FILL

public static final int FILL
Indicates cell should fill available space.

See Also:
Constant Field Values

TOP

public static final int TOP
Indicates top alignment of a cell.

See Also:
Constant Field Values

BOTTOM

public static final int BOTTOM
Indicates bottom alignment of a cell.

See Also:
Constant Field Values

rows

protected int rows

cols

protected int cols

vgap

protected int vgap

hgap

protected int hgap

topBorder

protected int topBorder

leftBorder

protected int leftBorder

bottomBorder

protected int bottomBorder

rightBorder

protected int rightBorder

minW

protected int minW

minH

protected int minH

rowScale

protected double[] rowScale

columnScale

protected double[] columnScale

hAlignment

protected int hAlignment

vAlignment

protected int vAlignment

hAlignments

protected int[][] hAlignments

vAlignments

protected int[][] vAlignments

rowSizes

protected int[] rowSizes

columnSizes

protected int[] columnSizes
Constructor Detail

SGLayout

public SGLayout()
Creates a default (2 x 2) layout. Horizontal and vertical gaps are set to 0 and X- and Y-alignments are set to FILL.


SGLayout

public SGLayout(int rows,
                int cols)
Creates a layout with the specified number of rows and columns. Horizontal and vertical gaps are set to 0 and X- and Y-alignments are set to FILL.

Parameters:
rows - Number of rows.
cols - Number of columns.

SGLayout

public SGLayout(int rows,
                int cols,
                int hgap,
                int vgap)
Creates a layout with the specified number of rows and columns and specified gaps. X- and Y-alignments are set to FILL.

Parameters:
rows - Number of rows.
cols - Number of columns.
hgap - The horizontal gap, in pixels.
vgap - The vertical gap, in pixels.

SGLayout

public SGLayout(int rows,
                int cols,
                int hAlignment,
                int vAlignment,
                int hgap,
                int vgap)
Creates a layout with the specified number of rows and columns, specified gaps and aligment properties.

Parameters:
rows - Number of rows.
cols - Number of columns.
hAlignment - The X-alignment (LEFT, RIGHT, CENTER or FILL).
vAlignment - the Y-alignment (TOP, BOTTOM, CENTER or FILL).
hgap - The horizontal gap, in pixels.
vgap - The vertical gap, in pixels.
Method Detail

setMargins

public void setMargins(int topBorder,
                       int leftBorder,
                       int bottomBorder,
                       int rightBorder)
Sets up the margins for the whole layout.

Parameters:
topBorder - The top border (in pixels).
leftBorder - The left border (in pixels).
bottomBorder - The bottom border (in pixels).
rightBorder - The right border (in pixels).

setRowScale

public void setRowScale(int index,
                        double prop)
Sets up scale value for a specific row.

Parameters:
index - The row number to scale.
prop - The scale value for the row.

setColumnScale

public void setColumnScale(int index,
                           double prop)
Sets up scale value for a specific column.

Parameters:
index - The column number to scale.
prop - The scale value for the column.

setAlignment

public void setAlignment(int row,
                         int col,
                         int hAlignment,
                         int vAlignment)
Set up alignment for a specific cell.

Parameters:
row - The row value of the cell to align.
col - The column value of the cell to align.
hAlignment - The X-alignment (LEFT, RIGHT, CENTER or FILL).
vAlignment - the Y-alignment (TOP, BOTTOM, CENTER or FILL).

setRowAlignment

public void setRowAlignment(int row,
                            int hAlignment,
                            int vAlignment)
Set up alignment for a specific row.

Parameters:
row - The row to align.
hAlignment - The X-alignment (LEFT, RIGHT, CENTER or FILL).
vAlignment - the Y-alignment (TOP, BOTTOM, CENTER or FILL).

setColumnAlignment

public void setColumnAlignment(int col,
                               int hAlignment,
                               int vAlignment)
Set up alignment for a specific column.

Parameters:
col - The column to align.
hAlignment - The X-alignment (LEFT, RIGHT, CENTER or FILL).
vAlignment - the Y-alignment (TOP, BOTTOM, CENTER or FILL).

addLayoutComponent

public void addLayoutComponent(String name,
                               Component comp)
Adds a component to the layout, but does nothing in this case.

Specified by:
addLayoutComponent in interface LayoutManager

removeLayoutComponent

public void removeLayoutComponent(Component comp)
Adds a component to the layout, but does nothing in this case.

Specified by:
removeLayoutComponent in interface LayoutManager

preferredLayoutSize

public Dimension preferredLayoutSize(Container parent)
Determines the preferred size of the container argument using this grid layout. The preferred width is the width of the largest row of children, which is the largest sum of preferred widths. The preferred height is the sum of the the largest heights of the rows, which is the largest preferred height in each row.

Specified by:
preferredLayoutSize in interface LayoutManager
Parameters:
parent - The container in which to do the layout.
Returns:
The preferred dimensions to lay out the subcomponents of the specified container.

minimumLayoutSize

public Dimension minimumLayoutSize(Container parent)
Determines the minimum size of the container argument using this grid layout. The preferred width is the width of the largest row of children, which is the largest sum of minimum widths. The preferred height is the sum of the the largest heights of the rows, which is the largest minimum height in each row.

Specified by:
minimumLayoutSize in interface LayoutManager
Parameters:
parent - The container in which to do the layout.
Returns:
The preferred dimensions to lay out the subcomponents of the specified container.

layoutContainer

public void layoutContainer(Container parent)
Lays out the specified container using this layout within the calculated grids.

Specified by:
layoutContainer in interface LayoutManager
Parameters:
parent - the container to be laid out.

allocateMaxSizes

protected void allocateMaxSizes(Container parent)
Update the maximum sizes for each of the grid cells using the specified scale values for rows and columns.

Parameters:
parent - the container to be laid out.


Copyright Jo Wood, 1996-2004, last modified, 3rd September, 2004