Class PercentData

  • All Implemented Interfaces:
    Serializable

    public final class PercentData
    extends Object
    implements Serializable

    A constraints class used by PercentLayout.

    This class is used to define data needed by the percent layout manager when new components are added to the managed container. The main data stored in instances of this class is information about where in the logic grid maintained by the layout manager the new component should be placed, i.e. the coordinates of the cell and the number of cells in X and Y direction that are spanned.

    It is also possible to associate a PercentData object with row and column constraints. If these constraints are defined, they override the constraints set for the occupied column and row. This makes it possible e.g. to set a different alignment for a certain component, while the other components in this row or column use the default alignment.

    Another information stored in instances of this class is the so-called target cell. This information is evaluated only if multiple columns or rows are occupied. In this case the target column determines to which column the size of the associated component should be assigned. This is optional; if no target column is set, the associated component's width will not be taken into account when the minimum layout width is calculated. The same applies for the target row.

    Instances of this class are immutable and thus thread-safe. They are not created directly, but the nested Builder class is used for this purpose. A typical sequence for creating PercentData objects could look as follows:

     PercentData.Builder b = new PercentData.Builder();
     PercentData pd1 = b.xy(1, 2).create();
     PercentData pd2 = b.xy(1, 3).spanX(2).withColumnConstraints(columnConstr).create();
     

    Version:
    $Id: PercentData.java 205 2012-01-29 18:29:57Z oheger $
    Author:
    Oliver Heger
    See Also:
    CellConstraints, Serialized Form
    • Field Detail

      • POS_UNDEF

        public static final int POS_UNDEF
        Constant for an undefined cell position.
        See Also:
        Constant Field Values
    • Method Detail

      • getColumn

        public int getColumn()
        Returns the number of the column, in which the corresponding component is to be placed.
        Returns:
        the column number
      • getRow

        public int getRow()
        Returns the number of the row, in which the corresponding component it to be placed.
        Returns:
        the row number
      • getSpanX

        public int getSpanX()
        Returns the number of occupied columns.
        Returns:
        the number of occupied columns
      • getSpanY

        public int getSpanY()
        Returns the number of occupied rows.
        Returns:
        the number of occupied rows
      • getTargetColumn

        public int getTargetColumn()
        Returns the target column.
        Returns:
        the target column
      • getTargetRow

        public int getTargetRow()
        Returns the target row.
        Returns:
        the target row
      • getColumnConstraints

        public CellConstraints getColumnConstraints()
        Returns the associated constraints object for the column.
        Returns:
        the column constraints object (may be null )
      • getRowConstraints

        public CellConstraints getRowConstraints()
        Returns the associated constraints object for the row.
        Returns:
        the row constraints object (may be null )
      • getConstraints

        public CellConstraints getConstraints​(boolean vert)
        A convenience method for determining the cell constraints object for the specified orientation. This method is useful for some generic methods in PercentLayoutBase that can operate either on columns or on rows.
        Parameters:
        vert - the orientation flag (true for vertical, false for horizontal)
        Returns:
        the corresponding constraints object
      • buildString

        public void buildString​(StringBuilder buf)
        Appends a string representation of this object to the specified string buffer. This string contains the properties of this instance with their values. No further information (e.g. the class name) is written.
        Parameters:
        buf - the target buffer (must not be null)
        Throws:
        IllegalArgumentException - if the buffer is null
      • toString

        public String toString()
        Returns a string representation of this object.
        Overrides:
        toString in class Object
        Returns:
        a string representation
      • equals

        public boolean equals​(Object obj)
        Compares this object with another one. Two instances of PercentData are considered equal if all of their properties are equal.
        Overrides:
        equals in class Object
        Parameters:
        obj - the object to compare to
        Returns:
        a flag whether these objects are equal
      • hashCode

        public int hashCode()
        Returns a hash code for this object.
        Overrides:
        hashCode in class Object
        Returns:
        a hash code