Class CellConstraints

java.lang.Object
com.vaadin.featurepack.desktop.layouts.form.CellConstraints
All Implemented Interfaces:
Serializable, Cloneable

public class CellConstraints extends Object implements Cloneable, Serializable
Defines constraints for placing components inside the FormLayout. Constraints describe the components display area: gridX, gridY, grid width (column span), and grid height (row span). Cell constraints need to be set using FormLayout.setConstraints(Component, Object).

Most methods return this object to enable method chaining. Note, FormLayout implicitly clones the cell constraints instance when applying it to specific components.

See Also:
  • Field Details

    • DEFAULT

      public static final CellConstraints.Alignment DEFAULT
      Use the column's or row's default alignment.
    • FILL

      public static final CellConstraints.Alignment FILL
      Fill the cell either horizontally or vertically.
    • LEFT

      public static final CellConstraints.Alignment LEFT
      Put the component in the left.
    • CENTER

      public static final CellConstraints.Alignment CENTER
      Put the component in the center.
    • TOP

      public static final CellConstraints.Alignment TOP
      Put the component in the top.
    • BOTTOM

      public static final CellConstraints.Alignment BOTTOM
      Put the component in the bottom.
    • gridX

      public int gridX
      Describes the component's horizontal grid origin (starts at 1).
    • gridY

      public int gridY
      Describes the component's vertical grid origin (starts at 1).
    • gridWidth

      public int gridWidth
      Describes the component's horizontal grid extend (number of cells).
    • gridHeight

      public int gridHeight
      Describes the component's vertical grid extent (number of cells).
    • hAlign

      Describes the component's horizontal alignment.
    • vAlign

      Describes the component's vertical alignment.
  • Constructor Details

    • CellConstraints

      public CellConstraints()
      Constructs a default instance of CellConstraints.
    • CellConstraints

      public CellConstraints(int gridX, int gridY)
      Constructs an instance of CellConstraints for the given cell position.
      Parameters:
      gridX - the component's horizontal grid origin
      gridY - the component's vertical grid origin
    • CellConstraints

      public CellConstraints(int gridX, int gridY, CellConstraints.Alignment hAlign, CellConstraints.Alignment vAlign)
      Constructs an instance of CellConstraints for the given cell position and alignment.
      Parameters:
      gridX - the component's horizontal grid origin
      gridY - the component's vertical grid origin
      hAlign - the component's horizontal alignment
      vAlign - the component's vertical alignment
    • CellConstraints

      public CellConstraints(int gridX, int gridY, int gridWidth, int gridHeight)
      Constructs an instance of CellConstraints for the given cell position and size.
      Parameters:
      gridX - the component's horizontal grid origin
      gridY - the component's vertical grid origin
      gridWidth - the component's horizontal extent
      gridHeight - the component's vertical extent
    • CellConstraints

      public CellConstraints(int gridX, int gridY, int gridWidth, int gridHeight, CellConstraints.Alignment hAlign, CellConstraints.Alignment vAlign)
      Constructs an instance of CellConstraints for the given cell position, size and alignment.
      Parameters:
      gridX - the component's horizontal grid origin
      gridY - the component's vertical grid origin
      gridWidth - the component's horizontal extent
      gridHeight - the component's vertical extent
      hAlign - the component's horizontal alignment
      vAlign - the component's vertical alignment
      Throws:
      IndexOutOfBoundsException - if the grid origin or extent is negative
      NullPointerException - if the horizontal or vertical alignment is null
      IllegalArgumentException - if an alignment orientation is invalid
    • CellConstraints

      public CellConstraints(String encodedConstraints)
      Constructs an instance of CellConstraints from the given encoded string properties.

      Examples:

       new CellConstraints("1, 3");
       new CellConstraints("1, 3, left, bottom");
       new CellConstraints("1, 3, 2, 1, left, bottom");
       new CellConstraints("1, 3, 2, 1, l, b");
       
      Parameters:
      encodedConstraints - the constraints encoded as string
  • Method Details

    • xy

      public CellConstraints xy(int col, int row)
      Sets column and row origins; sets width and height to 1.
      Parameters:
      col - the new column index
      row - the new row index
      Returns:
      this
    • xy

      public CellConstraints xy(int col, int row, String encodedAlignments)
      Sets column and row origins; sets width and height to 1; decodes horizontal and vertical alignments from the given string.
      Parameters:
      col - the new column index
      row - the new row index
      encodedAlignments - describes the horizontal and vertical alignments
      Returns:
      this
      Throws:
      IllegalArgumentException - if an alignment orientation is invalid
    • xy

      public CellConstraints xy(int col, int row, CellConstraints.Alignment colAlign, CellConstraints.Alignment rowAlign)
      Sets the column and row origins; sets width and height to 1; set horizontal and vertical alignment using the specified objects.
      Parameters:
      col - the new column index
      row - the new row index
      colAlign - horizontal component alignment
      rowAlign - vertical component alignment
      Returns:
      this
    • xyw

      public CellConstraints xyw(int col, int row, int colSpan)
      Sets the column, row, and width; uses a height (row span) of 1.
      Parameters:
      col - the new column index
      row - the new row index
      colSpan - the column span or grid width
      Returns:
      this
    • xyw

      public CellConstraints xyw(int col, int row, int colSpan, String encodedAlignments)
      Sets the column, row, width, and height; decodes the horizontal and vertical alignments from the given string. Uses a height (row span) of 1.

      Examples:

       cc.xyw(1, 3, 7, "left, bottom");
       cc.xyw(1, 3, 7, "l, b");
       cc.xyw(1, 3, 2, "center, fill");
       cc.xyw(1, 3, 2, "c, f");
       
      Parameters:
      col - the new column index
      row - the new row index
      colSpan - the column span or grid width
      encodedAlignments - describes the horizontal and vertical alignments
      Returns:
      this
      Throws:
      IllegalArgumentException - if an alignment orientation is invalid
    • xyw

      public CellConstraints xyw(int col, int row, int colSpan, CellConstraints.Alignment colAlign, CellConstraints.Alignment rowAlign)
      Sets the column, row, width, and height; sets the horizontal and vertical alignment using the specified objects. Uses a height (row span) of 1.

      Examples:

       cc.xyw(1, 3, 2, CellConstraints.LEFT, CellConstraints.BOTTOM);
       cc.xyw(1, 3, 7, CellConstraints.CENTER, CellConstraints.FILL);
       
      Parameters:
      col - the new column index
      row - the new row index
      colSpan - the column span or grid width
      colAlign - horizontal component alignment
      rowAlign - vertical component alignment
      Returns:
      this
      Throws:
      IllegalArgumentException - if an alignment orientation is invalid
    • xywh

      public CellConstraints xywh(int col, int row, int colSpan, int rowSpan)
      Sets the column, row, width, and height.
      Parameters:
      col - the new column index
      row - the new row index
      colSpan - the column span or grid width
      rowSpan - the row span or grid height
      Returns:
      this
    • xywh

      public CellConstraints xywh(int col, int row, int colSpan, int rowSpan, String encodedAlignments)
      Sets the column, row, width, and height; decodes the horizontal and vertical alignments from the given string.

      Parameters:
      col - the new column index
      row - the new row index
      colSpan - the column span or grid width
      rowSpan - the row span or grid height
      encodedAlignments - describes the horizontal and vertical alignments
      Returns:
      this
      Throws:
      IllegalArgumentException - if an alignment orientation is invalid
    • xywh

      public CellConstraints xywh(int col, int row, int colSpan, int rowSpan, CellConstraints.Alignment colAlign, CellConstraints.Alignment rowAlign)
      Sets the column, row, width, and height; sets the horizontal and vertical alignment using the specified alignment objects.

      Parameters:
      col - the new column index
      row - the new row index
      colSpan - the column span or grid width
      rowSpan - the row span or grid height
      colAlign - horizontal component alignment
      rowAlign - vertical component alignment
      Returns:
      this
      Throws:
      IllegalArgumentException - if an alignment orientation is invalid
    • clone

      public CellConstraints clone()
      Creates a copy of this cell constraints object.
      Overrides:
      clone in class Object
      Returns:
      a copy of this cell constraints object