Package net.sf.jguiraffe.gui.layout
Class CellConstraints.Builder
- java.lang.Object
-
- net.sf.jguiraffe.gui.layout.CellConstraints.Builder
-
- Enclosing class:
- CellConstraints
public static final class CellConstraints.Builder extends Object
A builder class for creating instances of
CellConstraints.With the different
withXXXX()methods the properties of the newCellConstraintsobject are defined. Then, with thecreate()method, the instance is actually created. Alternatively, with theparse()method aCellConstraintsinstance for a string representation can be requested.This class is not thread-safe. It maintains an internal (unsynchronized) cache of the
CellConstraintsinstances that have already been created. If instances with equal properties are requested, the same instance is returned.More information including a usage example of this class can be found in the documentation for
CellConstraints.- Version:
- $Id: CellConstraints.java 205 2012-01-29 18:29:57Z oheger $
- Author:
- Oliver Heger
-
-
Constructor Summary
Constructors Constructor Description Builder()Creates a new instance ofBuilder.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description CellConstraintscreate()Returns aCellConstraintsinstance for the properties defined so far.CellConstraints.BuilderdefaultColumn()Initializes the properties of theCellConstraintsinstance to be created with default values for a column.CellConstraints.BuilderdefaultRow()Initializes the properties of theCellConstraintsinstance to be created with default values for a row.CellConstraintsfromString(String spec)Parses a string with the specification of aCellConstraintsobject and returns a corresponding instance.CellAlignmentgetDefaultAlignment()Returns the defaultCellAlignmentused by this builder.voidreset()Resets all properties set so far.voidsetDefaultAlignment(CellAlignment defaultAlignment)Sets the defaultCellAlignmentused by this builder.CellConstraints.BuilderwithCellAlignment(CellAlignment align)Sets thealignmentproperty of theCellConstraintsinstance to be created.CellConstraints.BuilderwithCellSize(CellSize sz)Sets thesizeproperty of theCellConstraintsinstance to be created.CellConstraints.BuilderwithMinimumSize(NumberWithUnit minSize)Sets theminimumSizeproperty of theCellConstraintsinstance to be created.CellConstraints.BuilderwithWeight(int factor)Sets theweightproperty of theCellConstraintsinstance to be created.
-
-
-
Method Detail
-
getDefaultAlignment
public CellAlignment getDefaultAlignment()
Returns the defaultCellAlignmentused by this builder.- Returns:
- the default
CellAlignment
-
setDefaultAlignment
public void setDefaultAlignment(CellAlignment defaultAlignment)
Sets the defaultCellAlignmentused by this builder. This alignment is set by thereset()method. Note: after calling this methodreset()must be called to apply the new default alignment.- Parameters:
defaultAlignment- the new default alignment (must not be null)- Throws:
IllegalArgumentException- if the parameter is null
-
withCellSize
public CellConstraints.Builder withCellSize(CellSize sz)
Sets thesizeproperty of theCellConstraintsinstance to be created.- Parameters:
sz- the size of the cell (must not be null)- Returns:
- a reference to this builder for method chaining
- Throws:
IllegalArgumentException- if theCellSizeobject is null
-
withMinimumSize
public CellConstraints.Builder withMinimumSize(NumberWithUnit minSize)
Sets theminimumSizeproperty of theCellConstraintsinstance to be created.- Parameters:
minSize- the minimum size of the cell (can be null, then a minimum size of 0 pixels is assumed)- Returns:
- a reference to this builder for method chaining
- Throws:
IllegalArgumentException- if the value of the minimum size is negative
-
withCellAlignment
public CellConstraints.Builder withCellAlignment(CellAlignment align)
Sets thealignmentproperty of theCellConstraintsinstance to be created.- Parameters:
align- the alignment of the cell (must not be null)- Returns:
- a reference to this builder for method chaining
- Throws:
IllegalArgumentException- if the alignment is null
-
withWeight
public CellConstraints.Builder withWeight(int factor)
Sets theweightproperty of theCellConstraintsinstance to be created. This must be a positive number.- Parameters:
factor- the weight factor- Returns:
- a reference to this builder for method chaining
- Throws:
IllegalArgumentException- if the number is less than 0
-
defaultColumn
public CellConstraints.Builder defaultColumn()
Initializes the properties of theCellConstraintsinstance to be created with default values for a column. This means:- the alignment is set to
FULL - the size is set to
PREFERRED - no minimum size is set
- the weight factor is set to 0
withXXXX()methods specific values can be set.- Returns:
- a reference to this builder for method chaining
- the alignment is set to
-
defaultRow
public CellConstraints.Builder defaultRow()
Initializes the properties of theCellConstraintsinstance to be created with default values for a row. This means:- the alignment is set to
CENTER - the size is set to
PREFERRED - no minimum size is set
- the weight factor is set to 0
withXXXX()methods specific values can be set.- Returns:
- a reference to this builder for method chaining
- the alignment is set to
-
create
public CellConstraints create()
Returns aCellConstraintsinstance for the properties defined so far. After that all properties are reset, so that properties for a new instance can be specified.- Returns:
- a
CellConstraintsinstance corresponding to the properties set so far - Throws:
IllegalStateException- if required properties are missing
-
reset
public void reset()
Resets all properties set so far. This reverts all invocations ofwithXXXX()methods since the last instance was created.
-
fromString
public CellConstraints fromString(String spec)
Parses a string with the specification of aCellConstraintsobject and returns a corresponding instance.- Parameters:
spec- the specification of theCellConstraintsinstance- Returns:
- the corresponding
CellConstraintsinstance - Throws:
IllegalArgumentException- if the string cannot be parsed
-
-