Package net.sf.jguiraffe.gui.layout
Class PercentData.Builder
- java.lang.Object
-
- net.sf.jguiraffe.gui.layout.PercentData.Builder
-
- All Implemented Interfaces:
Serializable
- Enclosing class:
- PercentData
public static class PercentData.Builder extends Object implements Serializable
A builder implementation for creating instances of
PercentData. Using this classPercentDataobjects with all properties supported can be created in a convenient way. Refer to the class comment forPercentDatafor example use cases for this class.Implementation note: This class is not thread-safe.
- Version:
- $Id: PercentData.java 205 2012-01-29 18:29:57Z oheger $
- Author:
- Oliver Heger
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description Builder()Creates a new instance ofBuilder.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description PercentDatacreate()Creates thePercentDatainstance whose properties were specified by the preceding method calls.PercentDatapos(int x, int y)Returns aPercentDataobject with the specified column and row index.voidreset()Resets all properties of this builder to default values.PercentData.Builderspan(int w, int h)Initializes the number of columns and rows occupied by the component association with thePercentDatainstance to be created.PercentData.BuilderspanX(int w)Initializes the number of columns occupied by the component associated with thePercentDatainstance to be created.PercentData.BuilderspanY(int h)Initializes the number of rows occupied by the component associated with thePercentDatainstance to be created.PercentData.BuilderwithColumnConstraints(CellConstraints cc)Sets aCellConstraintsreference for the column for thePercentDatainstance to be created.PercentData.BuilderwithRowConstraints(CellConstraints cc)Sets aCellConstraintsreference for the row for thePercentDatainstance to be created.PercentData.BuilderwithTargetColumn(int tc)Initializes thetargetColumnproperty of thePercentDatainstance to be created.PercentData.BuilderwithTargetRow(int tr)Initializes thetargetRowproperty of thePercentDatainstance to be created.PercentData.Builderxy(int x, int y)Initializes the column and the row index of thePercentDatainstance to be created.
-
-
-
Method Detail
-
xy
public PercentData.Builder xy(int x, int y)
Initializes the column and the row index of thePercentDatainstance to be created.- Parameters:
x- the column index (must be greater or equal 0)y- the row index (must be greater or equal 0)- Returns:
- a reference to this builder for method chaining
- Throws:
IllegalArgumentException- if a parameter is invalid
-
spanX
public PercentData.Builder spanX(int w)
Initializes the number of columns occupied by the component associated with thePercentDatainstance to be created. This value is used to populate thespanXproperty of thePercentDataobject.- Parameters:
w- the number of occupied columns (must be greater 0)- Returns:
- a reference to this builder for method chaining
- Throws:
IllegalArgumentException- if the number of columns is less or equal 0
-
spanY
public PercentData.Builder spanY(int h)
Initializes the number of rows occupied by the component associated with thePercentDatainstance to be created. This value is used to populate thespanYproperty of thePercentDataobject.- Parameters:
h- the number of occupied rows (must be greater 0)- Returns:
- a reference to this builder for method chaining
- Throws:
IllegalArgumentException- if the number of rows is less or equal 0
-
span
public PercentData.Builder span(int w, int h)
Initializes the number of columns and rows occupied by the component association with thePercentDatainstance to be created. This is convenience method that combines calls tospanX(int)andspanY(int).- Parameters:
w- the number of occupied columns (must be greater 0)h- the number of occupied rows (must be greater 0)- Returns:
- a reference to this builder for method chaining
- Throws:
IllegalArgumentException- if the number of columns or rows is less or equal 0
-
withTargetColumn
public PercentData.Builder withTargetColumn(int tc)
Initializes thetargetColumnproperty of thePercentDatainstance to be created. If a component spans multiple columns, the target column specifies, to which column the size of the component should be applied. If no target column is set (which is the default), the width of the component is not taken into account when determining the width of the layout's columns.- Parameters:
tc- the index of the target column (must be greater or equal 0)- Returns:
- a reference to this builder for method chaining
- Throws:
IllegalArgumentException- if the target column is less than 0
-
withTargetRow
public PercentData.Builder withTargetRow(int tr)
Initializes thetargetRowproperty of thePercentDatainstance to be created. If a component spans multiple rows, the target row specifies, to which row the size of the component should be applied. If no target row is set (which is the default), the height of the component is not taken into account when determining the height of the layout's rows.- Parameters:
tr- the index of the target row (must be greater or equal 0)- Returns:
- a reference to this builder for method chaining
- Throws:
IllegalArgumentException- if the target row is less than 0
-
withColumnConstraints
public PercentData.Builder withColumnConstraints(CellConstraints cc)
Sets aCellConstraintsreference for the column for thePercentDatainstance to be created. With this method thecolumnConstraintsproperty of thePercentDataobject can be specified.- Parameters:
cc- theCellConstraintsobject for the column- Returns:
- a reference to this builder for method chaining
-
withRowConstraints
public PercentData.Builder withRowConstraints(CellConstraints cc)
Sets aCellConstraintsreference for the row for thePercentDatainstance to be created. With this method therowConstraintsproperty of thePercentDataobject can be specified.- Parameters:
cc- theCellConstraintsobject for the row- Returns:
- a reference to this builder for method chaining
-
pos
public PercentData pos(int x, int y)
Returns aPercentDataobject with the specified column and row index. This is a convenience method for the frequent use case that only the position of a component in the layout needs to be specified. It has the same effect as callingxy(int, int)followed bycreate(). Properties that have been set before are not cleared.- Parameters:
x- the column index (must be greater or equal 0)y- the row index (must be greater or equal 0)- Returns:
- the
PercentDataobject with the given coordinates - Throws:
IllegalArgumentException- if a parameter is invalid
-
create
public PercentData create()
Creates thePercentDatainstance whose properties were specified by the preceding method calls. This method requires that the position was set using thexy(int, int)method. All other properties are optional and are initialized with the following default values:- The span is set to (1, 1), i.e. the component covers a single column and row.
- The target column and row are set to -1, which means that they are undefined.
- The column constraints and row constraints are set to null.
- Returns:
- a reference to the new
PercentDatainstance - Throws:
IllegalStateException- if required parameters have not been set
-
reset
public void reset()
Resets all properties of this builder to default values. This method is automatically called bycreate(), so that the definition of a new instance can be started. It can be invoked manually to undo the effects of methods called before.
-
-