Class 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 class PercentData objects with all properties supported can be created in a convenient way. Refer to the class comment for PercentData 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 Detail

      • Builder

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

      • xy

        public PercentData.Builder xy​(int x,
                                      int y)
        Initializes the column and the row index of the PercentData 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 the PercentData instance to be created. This value is used to populate the spanX property of the PercentData 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 the PercentData instance to be created. This value is used to populate the spanY property of the PercentData 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 the PercentData instance to be created. This is convenience method that combines calls to spanX(int) and spanY(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 the targetColumn property of the PercentData 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 the targetRow property of the PercentData 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 a CellConstraints reference for the column for the PercentData instance to be created. With this method the columnConstraints property of the PercentData object can be specified.
        Parameters:
        cc - the CellConstraints object for the column
        Returns:
        a reference to this builder for method chaining
      • withRowConstraints

        public PercentData.Builder withRowConstraints​(CellConstraints cc)
        Sets a CellConstraints reference for the row for the PercentData instance to be created. With this method the rowConstraints property of the PercentData object can be specified.
        Parameters:
        cc - the CellConstraints object for the row
        Returns:
        a reference to this builder for method chaining
      • pos

        public PercentData pos​(int x,
                               int y)
        Returns a PercentData 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 calling xy(int, int) followed by create(). 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 the PercentData instance whose properties were specified by the preceding method calls. This method requires that the position was set using the xy(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 by create(), so that the definition of a new instance can be started. It can be invoked manually to undo the effects of methods called before.