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 classPercentData
objects with all properties supported can be created in a convenient way. Refer to the class comment forPercentData
for 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 PercentData
create()
Creates thePercentData
instance whose properties were specified by the preceding method calls.PercentData
pos(int x, int y)
Returns aPercentData
object with the specified column and row index.void
reset()
Resets all properties of this builder to default values.PercentData.Builder
span(int w, int h)
Initializes the number of columns and rows occupied by the component association with thePercentData
instance to be created.PercentData.Builder
spanX(int w)
Initializes the number of columns occupied by the component associated with thePercentData
instance to be created.PercentData.Builder
spanY(int h)
Initializes the number of rows occupied by the component associated with thePercentData
instance to be created.PercentData.Builder
withColumnConstraints(CellConstraints cc)
Sets aCellConstraints
reference for the column for thePercentData
instance to be created.PercentData.Builder
withRowConstraints(CellConstraints cc)
Sets aCellConstraints
reference for the row for thePercentData
instance to be created.PercentData.Builder
withTargetColumn(int tc)
Initializes thetargetColumn
property of thePercentData
instance to be created.PercentData.Builder
withTargetRow(int tr)
Initializes thetargetRow
property of thePercentData
instance to be created.PercentData.Builder
xy(int x, int y)
Initializes the column and the row index of thePercentData
instance to be created.
-
-
-
Method Detail
-
xy
public PercentData.Builder xy(int x, int y)
Initializes the column and the row index of thePercentData
instance 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 thePercentData
instance to be created. This value is used to populate thespanX
property of thePercentData
object.- 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 thePercentData
instance to be created. This value is used to populate thespanY
property of thePercentData
object.- 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 thePercentData
instance 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 thetargetColumn
property of thePercentData
instance 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 thetargetRow
property of thePercentData
instance 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 aCellConstraints
reference for the column for thePercentData
instance to be created. With this method thecolumnConstraints
property of thePercentData
object can be specified.- Parameters:
cc
- theCellConstraints
object for the column- Returns:
- a reference to this builder for method chaining
-
withRowConstraints
public PercentData.Builder withRowConstraints(CellConstraints cc)
Sets aCellConstraints
reference for the row for thePercentData
instance to be created. With this method therowConstraints
property of thePercentData
object can be specified.- Parameters:
cc
- theCellConstraints
object for the row- Returns:
- a reference to this builder for method chaining
-
pos
public PercentData pos(int x, int y)
Returns aPercentData
object 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
PercentData
object with the given coordinates - Throws:
IllegalArgumentException
- if a parameter is invalid
-
create
public PercentData create()
Creates thePercentData
instance 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
PercentData
instance - 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.
-
-