Class 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 new CellConstraints object are defined. Then, with the create() method, the instance is actually created. Alternatively, with the parse() method a CellConstraints 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 Detail

      • Builder

        public Builder()
        Creates a new instance of Builder.
    • Method Detail

      • getDefaultAlignment

        public CellAlignment getDefaultAlignment()
        Returns the default CellAlignment used by this builder.
        Returns:
        the default CellAlignment
      • setDefaultAlignment

        public void setDefaultAlignment​(CellAlignment defaultAlignment)
        Sets the default CellAlignment used by this builder. This alignment is set by the reset() method. Note: after calling this method reset() 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
      • withMinimumSize

        public CellConstraints.Builder withMinimumSize​(NumberWithUnit minSize)
        Sets the minimumSize property of the CellConstraints 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
      • withWeight

        public CellConstraints.Builder withWeight​(int factor)
        Sets the weight property of the CellConstraints 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 the CellConstraints 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
        This method can be called first for initializing default values. Then, with other withXXXX() methods specific values can be set.
        Returns:
        a reference to this builder for method chaining
      • defaultRow

        public CellConstraints.Builder defaultRow()
        Initializes the properties of the CellConstraints 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
        This method can be called first for initializing default values. Then, with other withXXXX() methods specific values can be set.
        Returns:
        a reference to this builder for method chaining
      • create

        public CellConstraints create()
        Returns a CellConstraints 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 of withXXXX() methods since the last instance was created.
      • fromString

        public CellConstraints fromString​(String spec)
        Parses a string with the specification of a CellConstraints object and returns a corresponding instance.
        Parameters:
        spec - the specification of the CellConstraints instance
        Returns:
        the corresponding CellConstraints instance
        Throws:
        IllegalArgumentException - if the string cannot be parsed