com.jgoodies.forms.builder

Class AbstractFormBuilder

public abstract class AbstractFormBuilder extends Object

An abstract class that minimizes the effort required to implement non-visual builders that use the FormLayout.

Builders hide details of the FormLayout and provide convenience behavior that assists you in constructing a form. This class provides a cell cursor that helps you traverse a form while you add components. Also, it offers several methods to append custom and logical columns and rows.

Version: $Revision: 1.9 $

Author: Karsten Lentzsch

See Also: ButtonBarBuilder ButtonStackBuilder PanelBuilder I15dPanelBuilder DefaultFormBuilder

Constructor Summary
AbstractFormBuilder(FormLayout layout, Container container)
Constructs a AbstractFormBuilder for the given FormLayout and layout container.
Method Summary
Componentadd(Component component, CellConstraints cellConstraints)
Adds a component to the panel using the given cell constraints.
Componentadd(Component component, String encodedCellConstraints)
Adds a component to the panel using the given encoded cell constraints.
Componentadd(Component component)
Adds a component to the container using the default cell constraints.
voidappendColumn(ColumnSpec columnSpec)
Appends the given column specification to the builder's layout.
voidappendColumn(String encodedColumnSpec)
Appends a column specification to the builder's layout that represents the given string encoding.
voidappendGlueColumn()
Appends a glue column.
voidappendGlueRow()
Appends a glue row.
voidappendLabelComponentsGapColumn()
Appends a column that is the default gap between a label and its associated component.
voidappendParagraphGapRow()
Appends a row that is the default gap for paragraphs.
voidappendRelatedComponentsGapColumn()
Appends a column that is the default gap for related components.
voidappendRelatedComponentsGapRow()
Appends a row that is the default gap for related components.
voidappendRow(RowSpec rowSpec)
Appends the given row specification to the builder's layout.
voidappendRow(String encodedRowSpec)
Appends a row specification to the builder's layout that represents the given string encoding.
voidappendUnrelatedComponentsGapColumn()
Appends a column that is the default gap for unrelated components.
voidappendUnrelatedComponentsGapRow()
Appends a row that is the default gap for unrelated components.
protected CellConstraintscellConstraints()
Returns the CellConstraints object that is used as a cursor and holds the current column span and row span.
protected CellConstraintscreateLeftAdjustedConstraints(int columnSpan)
Creates and returns a CellConstraints object at the current cursor position that uses the given column span and is adjusted to the left.
intgetColumn()
Returns the cursor's column.
intgetColumnCount()
Returns the number of columns in the form.
protected intgetColumnIncrementSign()
Returns the sign (-1 or 1) used to increment the cursor's column when moving to the next column.
ContainergetContainer()
Returns the container used to build the form.
FormLayoutgetLayout()
Returns the instance of FormLayout used to build this form.
protected intgetLeadingColumn()
Returns the index of the leading column.

Subclasses may override this method, for example, if the form has a leading gap column that should not be filled with components.

intgetRow()
Returns the cursor's row.
intgetRowCount()
Returns the number of rows in the form.
booleanisLeftToRight()
Returns whether this builder fills the form left-to-right or right-to-left.
voidnextColumn()
Moves to the next column, does the same as #nextColumn(1).
voidnextColumn(int columns)
Moves to the next column.
voidnextLine()
Moves to the next line: increases the row and resets the column; does the same as #nextLine(1).
voidnextLine(int lines)
Moves the cursor down several lines: increases the row by the specified number of lines and sets the cursor to the leading column.
voidnextRow()
Increases the row by one; does the same as #nextRow(1).
voidnextRow(int rows)
Increases the row by the specified rows.
voidsetAlignment(CellConstraints.Alignment hAlign, CellConstraints.Alignment vAlign)
Sets the horizontal and vertical alignment.
voidsetBounds(int column, int row, int columnSpan, int rowSpan)
Sets the cell bounds (location and extent) to the given column, row, column span and row span.
voidsetColumn(int column)
Sets the cursor to the given column.
voidsetColumnSpan(int columnSpan)
Sets the cursor's column span.
voidsetExtent(int columnSpan, int rowSpan)
Sets the cursor's extent to the given column span and row span.
voidsetHAlignment(CellConstraints.Alignment alignment)
Sets the horizontal alignment.
voidsetLeftToRight(boolean b)
Sets the form fill direction to left-to-right or right-to-left.
voidsetOrigin(int column, int row)
Sets the cursor's origin to the given column and row.
voidsetRow(int row)
Sets the cursor to the given row.
voidsetRowSpan(int rowSpan)
Sets the cursor's row span.
voidsetVAlignment(CellConstraints.Alignment alignment)
Sets the vertical alignment.

Constructor Detail

AbstractFormBuilder

public AbstractFormBuilder(FormLayout layout, Container container)
Constructs a AbstractFormBuilder for the given FormLayout and layout container.

Parameters: layout the FormLayout to use container the layout container

Throws: NullPointerException if the layout or container is null

Method Detail

add

public final Component add(Component component, CellConstraints cellConstraints)
Adds a component to the panel using the given cell constraints.

Parameters: component the component to add cellConstraints the component's cell constraints

Returns: the added component

add

public final Component add(Component component, String encodedCellConstraints)
Adds a component to the panel using the given encoded cell constraints.

Parameters: component the component to add encodedCellConstraints the component's encoded cell constraints

Returns: the added component

add

public final Component add(Component component)
Adds a component to the container using the default cell constraints. Note that when building from left to right, this method won't adjust the cell constraints if the column span is larger than 1. In this case you should use AbstractFormBuilder with a cell constraints object created by AbstractFormBuilder.

Parameters: component the component to add

Returns: the added component

See Also: AbstractFormBuilder AbstractFormBuilder

appendColumn

public final void appendColumn(ColumnSpec columnSpec)
Appends the given column specification to the builder's layout.

Parameters: columnSpec the column specification object to append

See Also: appendColumn

appendColumn

public final void appendColumn(String encodedColumnSpec)
Appends a column specification to the builder's layout that represents the given string encoding.

Parameters: encodedColumnSpec the column specification to append in encoded form

See Also: appendColumn

appendGlueColumn

public final void appendGlueColumn()
Appends a glue column.

See Also: appendLabelComponentsGapColumn appendRelatedComponentsGapColumn appendUnrelatedComponentsGapColumn

appendGlueRow

public final void appendGlueRow()
Appends a glue row.

See Also: appendRelatedComponentsGapRow appendUnrelatedComponentsGapRow appendParagraphGapRow

appendLabelComponentsGapColumn

public final void appendLabelComponentsGapColumn()
Appends a column that is the default gap between a label and its associated component.

Since: 1.0.3

See Also: appendGlueColumn appendRelatedComponentsGapColumn appendUnrelatedComponentsGapColumn

appendParagraphGapRow

public final void appendParagraphGapRow()
Appends a row that is the default gap for paragraphs.

Since: 1.0.3

See Also: appendGlueRow appendRelatedComponentsGapRow appendUnrelatedComponentsGapRow

appendRelatedComponentsGapColumn

public final void appendRelatedComponentsGapColumn()
Appends a column that is the default gap for related components.

See Also: appendGlueColumn appendLabelComponentsGapColumn appendUnrelatedComponentsGapColumn

appendRelatedComponentsGapRow

public final void appendRelatedComponentsGapRow()
Appends a row that is the default gap for related components.

See Also: appendGlueRow appendUnrelatedComponentsGapRow appendParagraphGapRow

appendRow

public final void appendRow(RowSpec rowSpec)
Appends the given row specification to the builder's layout.

Parameters: rowSpec the row specification object to append

See Also: appendRow

appendRow

public final void appendRow(String encodedRowSpec)
Appends a row specification to the builder's layout that represents the given string encoding.

Parameters: encodedRowSpec the row specification to append in encoded form

See Also: appendRow

appendUnrelatedComponentsGapColumn

public final void appendUnrelatedComponentsGapColumn()
Appends a column that is the default gap for unrelated components.

See Also: appendGlueColumn appendLabelComponentsGapColumn appendRelatedComponentsGapColumn

appendUnrelatedComponentsGapRow

public final void appendUnrelatedComponentsGapRow()
Appends a row that is the default gap for unrelated components.

See Also: appendGlueRow appendRelatedComponentsGapRow appendParagraphGapRow

cellConstraints

protected final CellConstraints cellConstraints()
Returns the CellConstraints object that is used as a cursor and holds the current column span and row span.

Returns: the builder's current CellConstraints object

createLeftAdjustedConstraints

protected final CellConstraints createLeftAdjustedConstraints(int columnSpan)
Creates and returns a CellConstraints object at the current cursor position that uses the given column span and is adjusted to the left. Useful when building from right to left.

Parameters: columnSpan the column span to be used in the constraints

Returns: CellConstraints adjusted to the left hand side

getColumn

public final int getColumn()
Returns the cursor's column.

Returns: the cursor's column

getColumnCount

public final int getColumnCount()
Returns the number of columns in the form.

Returns: the number of columns

getColumnIncrementSign

protected final int getColumnIncrementSign()
Returns the sign (-1 or 1) used to increment the cursor's column when moving to the next column.

Returns: -1 for right-to-left, 1 for left-to-right

getContainer

public final Container getContainer()
Returns the container used to build the form.

Returns: the layout container

getLayout

public final FormLayout getLayout()
Returns the instance of FormLayout used to build this form.

Returns: the FormLayout

getLeadingColumn

protected int getLeadingColumn()
Returns the index of the leading column.

Subclasses may override this method, for example, if the form has a leading gap column that should not be filled with components.

Returns: the leading column

getRow

public final int getRow()
Returns the cursor's row.

Returns: the cursor's row

getRowCount

public final int getRowCount()
Returns the number of rows in the form.

Returns: the number of rows

isLeftToRight

public final boolean isLeftToRight()
Returns whether this builder fills the form left-to-right or right-to-left. The initial value of this property is set during the builder construction from the layout container's componentOrientation property.

Returns: true indicates left-to-right, false indicates right-to-left

See Also: AbstractFormBuilder ComponentOrientation

nextColumn

public final void nextColumn()
Moves to the next column, does the same as #nextColumn(1).

nextColumn

public final void nextColumn(int columns)
Moves to the next column.

Parameters: columns number of columns to move

nextLine

public final void nextLine()
Moves to the next line: increases the row and resets the column; does the same as #nextLine(1).

nextLine

public final void nextLine(int lines)
Moves the cursor down several lines: increases the row by the specified number of lines and sets the cursor to the leading column.

Parameters: lines number of rows to move

nextRow

public final void nextRow()
Increases the row by one; does the same as #nextRow(1).

nextRow

public final void nextRow(int rows)
Increases the row by the specified rows.

Parameters: rows number of rows to move

setAlignment

public final void setAlignment(CellConstraints.Alignment hAlign, CellConstraints.Alignment vAlign)
Sets the horizontal and vertical alignment.

Parameters: hAlign the new horizontal alignment vAlign the new vertical alignment

setBounds

public final void setBounds(int column, int row, int columnSpan, int rowSpan)
Sets the cell bounds (location and extent) to the given column, row, column span and row span.

Parameters: column the new column index (grid x) row the new row index (grid y) columnSpan the new column span (grid width) rowSpan the new row span (grid height)

setColumn

public final void setColumn(int column)
Sets the cursor to the given column.

Parameters: column the cursor's new column index

setColumnSpan

public final void setColumnSpan(int columnSpan)
Sets the cursor's column span.

Parameters: columnSpan the cursor's new column span (grid width)

setExtent

public final void setExtent(int columnSpan, int rowSpan)
Sets the cursor's extent to the given column span and row span.

Parameters: columnSpan the new column span (grid width) rowSpan the new row span (grid height)

setHAlignment

public final void setHAlignment(CellConstraints.Alignment alignment)
Sets the horizontal alignment.

Parameters: alignment the new horizontal alignment

setLeftToRight

public final void setLeftToRight(boolean b)
Sets the form fill direction to left-to-right or right-to-left. The initial value of this property is set during the builder construction from the layout container's componentOrientation property.

Parameters: b true indicates left-to-right, false right-to-left

See Also: isLeftToRight ComponentOrientation

setOrigin

public final void setOrigin(int column, int row)
Sets the cursor's origin to the given column and row.

Parameters: column the new column index row the new row index

setRow

public final void setRow(int row)
Sets the cursor to the given row.

Parameters: row the cursor's new row index

setRowSpan

public final void setRowSpan(int rowSpan)
Sets the cursor's row span.

Parameters: rowSpan the cursor's new row span (grid height)

setVAlignment

public final void setVAlignment(CellConstraints.Alignment alignment)
Sets the vertical alignment.

Parameters: alignment the new vertical alignment

Copyright © 2002-2008 JGoodies Karsten Lentzsch. All Rights Reserved.