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 newCellConstraints
object are defined. Then, with thecreate()
method, the instance is actually created. Alternatively, with theparse()
method aCellConstraints
instance for a string representation can be requested.This class is not thread-safe. It maintains an internal (unsynchronized) cache of the
CellConstraints
instances 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 CellConstraints
create()
Returns aCellConstraints
instance for the properties defined so far.CellConstraints.Builder
defaultColumn()
Initializes the properties of theCellConstraints
instance to be created with default values for a column.CellConstraints.Builder
defaultRow()
Initializes the properties of theCellConstraints
instance to be created with default values for a row.CellConstraints
fromString(String spec)
Parses a string with the specification of aCellConstraints
object and returns a corresponding instance.CellAlignment
getDefaultAlignment()
Returns the defaultCellAlignment
used by this builder.void
reset()
Resets all properties set so far.void
setDefaultAlignment(CellAlignment defaultAlignment)
Sets the defaultCellAlignment
used by this builder.CellConstraints.Builder
withCellAlignment(CellAlignment align)
Sets thealignment
property of theCellConstraints
instance to be created.CellConstraints.Builder
withCellSize(CellSize sz)
Sets thesize
property of theCellConstraints
instance to be created.CellConstraints.Builder
withMinimumSize(NumberWithUnit minSize)
Sets theminimumSize
property of theCellConstraints
instance to be created.CellConstraints.Builder
withWeight(int factor)
Sets theweight
property of theCellConstraints
instance to be created.
-
-
-
Method Detail
-
getDefaultAlignment
public CellAlignment getDefaultAlignment()
Returns the defaultCellAlignment
used by this builder.- Returns:
- the default
CellAlignment
-
setDefaultAlignment
public void setDefaultAlignment(CellAlignment defaultAlignment)
Sets the defaultCellAlignment
used 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 thesize
property of theCellConstraints
instance 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 theCellSize
object is null
-
withMinimumSize
public CellConstraints.Builder withMinimumSize(NumberWithUnit minSize)
Sets theminimumSize
property of theCellConstraints
instance 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 thealignment
property of theCellConstraints
instance 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 theweight
property of theCellConstraints
instance 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 theCellConstraints
instance 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 theCellConstraints
instance 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 aCellConstraints
instance for the properties defined so far. After that all properties are reset, so that properties for a new instance can be specified.- Returns:
- a
CellConstraints
instance 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 aCellConstraints
object and returns a corresponding instance.- Parameters:
spec
- the specification of theCellConstraints
instance- Returns:
- the corresponding
CellConstraints
instance - Throws:
IllegalArgumentException
- if the string cannot be parsed
-
-