net.returnvoid.graphics.grid

## Class TableGrid

- java.lang.Object
- - net.returnvoid.graphics.grid.TableGrid

- All Implemented Interfaces:
    RGrid

      public class TableGrid
      extends java.lang.Object
      implements RGrid

  This class helps to build an table grid (a grid that is defined by rows and columns). The elements will be distributed evenly.
  Author:
    Diana Lange

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `TableGrid(float x, float y, float w, float h, int columns, int rows, float paddingX, float paddingY)` Builds a new grid.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `java.lang.Float` | `cellHeight()` Returns the height of any element in this grid.
    `java.lang.Float` | `cellWidth()` Returns the width of any element in this grid.
    `java.lang.Integer` | `columns()` Returns the number of columns of this grid.
    `java.lang.Integer` | `getColumn(int index)` Returns the column index [0, rows()] with a given element index.
    `java.lang.Float` | `getColumnX(java.lang.Integer columnIndex)` Returns the x-location of the column with a given column index.
    `java.lang.Float` | `getColumnY(java.lang.Integer columnIndex)` Returns the y-location of the column with a given column index.
    `processing.core.PVector[]` | `getCoordinates()` Returns all positions of all elements in the grid.
    `java.lang.Float` | `getHeight()` Returns the current height of the grid.
    `java.lang.Float` | `getHeight(java.lang.Integer i)` Returns the current height of the grid.
    `java.lang.Float` | `getPadding()` Returns the space between the elements of the grid.
    `java.lang.Float` | `getPaddingX()` Returns the horizontal padding of this grid.
    `java.lang.Float` | `getPaddingY()` Returns the vertical padding of this grid.
    `java.lang.Integer` | `getRow(java.lang.Integer index)` Returns the row index [0, rows()] with a given element index.
    `java.lang.Float` | `getRowX(java.lang.Integer rowIndex)` Returns the x-location of the row with a given row index.
    `java.lang.Float` | `getRowY(java.lang.Integer rowIndex)` Returns the y-location of the row with a given row index.
    `java.lang.Float` | `getWidth()` Returns the width of the element at the given index.
    `java.lang.Float` | `getWidth(java.lang.Integer i)` Returns the current width of the grid.
    `java.lang.Float` | `getX()` Returns the current x-position of the grid.
    `java.lang.Float` | `getX(java.lang.Integer index)` Returns the x-position of the element at the given index.
    `java.lang.Float` | `getY()` Returns the current y-position of the grid.
    `java.lang.Float` | `getY(java.lang.Integer index)` Returns the y-position of the element at the given index.
    `java.lang.Integer` | `index(java.lang.Integer row, java.lang.Integer column)` Returns the element index with given column and row index.
    `boolean` | `isEvenColumn(int index)` Returns if the element with the given index is member of an even column.
    `boolean` | `isEvenRow(int index)` Returns if the element with the given index is member of an even row.
    `java.lang.Integer` | `rows()` Returns the number of rows of this grid.
    `TableGrid` | `setCellHeight(float cellHeight)` Sets the height of the grid elements.
    `TableGrid` | `setCellWidth(float cellWidth)` Sets the width of the grid elements.
    `TableGrid` | `setColumns(java.lang.Integer columns)` Sets the number of columns for this grid.
    `TableGrid` | `setDimension(float s)` Sets the width and height of this grid (width and height will have the same value).
    `TableGrid` | `setDimension(float w, float h)` Sets the width and height of this grid.
    `TableGrid` | `setHeight(float h)` Sets the height of this grid.
    `TableGrid` | `setPadding()` Sets the horizontal and vertical padding.
    `TableGrid` | `setPadding(float padding)` Sets the horizontal and vertical padding.
    `TableGrid` | `setPaddingX()` Sets the horizontal padding.
    `TableGrid` | `setPaddingX(float paddingX)` Sets the horizontal padding.
    `TableGrid` | `setPaddingY()` Sets the vertical padding.
    `TableGrid` | `setPaddingY(float paddingY)` Sets the vertical padding.
    `TableGrid` | `setRows(java.lang.Integer rows)` Sets the number of rows for this grid.
    `TableGrid` | `setSize(java.lang.Integer size)` Sets the number of elements for this grid.
    `TableGrid` | `setWidth(float w)` Sets the width of this grid.
    `TableGrid` | `setX(float x)` Set to x-position of the grid.
    `TableGrid` | `setY(float y)` Set to y-position of the grid.
    `java.lang.Integer` | `size()` Returns the number of elements in the grid.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### TableGrid

          public TableGrid(float x,
                           float y,
                           float w,
                           float h,
                           int columns,
                           int rows,
                           float paddingX,
                           float paddingY)

      Builds a new grid. Please provide reasonable value for each parameter or use the GridMaker.
      Parameters:
        `x` - The x-location of the grid (top-left corner).
        `y` - The y-location of the grid (top-left corner).
        `w` - The width of the grid.
        `h` - The height of the grid.
        `columns` - The number of columns of the grid.
        `rows` - The number of rows of the grid.
        `paddingX` - The horizontal padding of the elements of the grid (>= 0).
        `paddingY` - The vertical padding of the elements of the grid (>= 0).

  - ### Method Detail

    - #### setX

          public TableGrid setX(float x)

      Description copied from interface: `RGrid`
      Set to x-position of the grid.
      Specified by:
        `setX` in interface `RGrid`
      Parameters:
        `x` - The new x-position of the grid.
      Returns:
        The current grid object.

    - #### setY

          public TableGrid setY(float y)

      Description copied from interface: `RGrid`
      Set to y-position of the grid.
      Specified by:
        `setY` in interface `RGrid`
      Parameters:
        `y` - The new y-position of the grid.
      Returns:
        The current grid object.

    - #### setWidth

          public TableGrid setWidth(float w)

      Sets the width of this grid.
      Parameters:
        `w` - The new grid width.
      Returns:
        The current grid object.

    - #### setHeight

          public TableGrid setHeight(float h)

      Sets the height of this grid.
      Parameters:
        `h` - The new grid height.
      Returns:
        The current grid object.

    - #### setDimension

          public TableGrid setDimension(float s)

      Sets the width and height of this grid (width and height will have the same value).
      Parameters:
        `s` - The new grid dimension (width and height).
      Returns:
        The current grid object.

    - #### setDimension

          public TableGrid setDimension(float w,
                                        float h)

      Sets the width and height of this grid.
      Parameters:
        `w` - The new grid width.
        `h` - The new grid height.
      Returns:
        The current grid object.

    - #### setCellWidth

          public TableGrid setCellWidth(float cellWidth)

      Sets the width of the grid elements. The maximum width for the elements is getWidth() / columns(). The horizontal padding will be changed after this method call.
      Parameters:
        `cellWidth` - The new width of the cells.
      Returns:
        The current grid object.

    - #### setCellHeight

          public TableGrid setCellHeight(float cellHeight)

      Sets the height of the grid elements. The maximum height for the elements is getHeight() / rows(). The vertical padding will be changed after this method call.
      Parameters:
        `cellHeight` - The new width of the cells.
      Returns:
        The current grid object.

    - #### setPadding

          public TableGrid setPadding()

      Sets the horizontal and vertical padding. The paddings will be equal to the width / height of the cells.
      Returns:
        The current grid object.

    - #### setPaddingX

          public TableGrid setPaddingX()

      Sets the horizontal padding. The padding will be equal to the width of the cells.
      Returns:
        The current grid object.

    - #### setPaddingY

          public TableGrid setPaddingY()

      Sets the vertical padding. The paddings will be equal to the height of the cells.
      Returns:
        The current grid object.

    - #### setPadding

          public TableGrid setPadding(float padding)

      Sets the horizontal and vertical padding.
      Specified by:
        `setPadding` in interface `RGrid`
      Parameters:
        `padding` - The new (horizontal / vertical) padding of this grid (>= 0).
      Returns:
        The current grid object.

    - #### setPaddingX

          public TableGrid setPaddingX(float paddingX)

      Sets the horizontal padding.
      Parameters:
        `paddingX` - The new horizontal padding of this grid (>= 0).
      Returns:
        The current grid object.

    - #### setPaddingY

          public TableGrid setPaddingY(float paddingY)

      Sets the vertical padding.
      Parameters:
        `paddingY` - The new vertical padding of this grid (>= 0).
      Returns:
        The current grid object.

    - #### setSize

          public TableGrid setSize(java.lang.Integer size)

      Sets the number of elements for this grid.
      Parameters:
        `size` - The new number of elements for this grid (>= 1).
      Returns:
        The current grid object.

    - #### setColumns

          public TableGrid setColumns(java.lang.Integer columns)

      Sets the number of columns for this grid.
      Parameters:
        `columns` - The new number of columns for this grid (>= 1).
      Returns:
        The current grid object.

    - #### setRows

          public TableGrid setRows(java.lang.Integer rows)

      Sets the number of rows for this grid.
      Parameters:
        `rows` - The new number of rows for this grid (>= 1).
      Returns:
        The current grid object.

    - #### getCoordinates

          public processing.core.PVector[] getCoordinates()

      Description copied from interface: `RGrid`
      Returns all positions of all elements in the grid.
      Specified by:
        `getCoordinates` in interface `RGrid`
      Returns:
        The positions.

    - #### columns

          public java.lang.Integer columns()

      Returns the number of columns of this grid.
      Returns:
        The number of columns.

    - #### rows

          public java.lang.Integer rows()

      Returns the number of rows of this grid.
      Returns:
        The number of rows.

    - #### size

          public java.lang.Integer size()

      Description copied from interface: `RGrid`
      Returns the number of elements in the grid. This is usefull if you want to iterate over all elements of the grid. Example:

           for (int i = 0; i < myGrid.size(); i++) {
                          float x = myGrid.getX(i);
                          float y = myGrid.getY(i):
           }

      Specified by:
        `size` in interface `RGrid`
      Returns:
        The number of elements of the grid.

    - #### getPaddingX

          public java.lang.Float getPaddingX()

      Returns the horizontal padding of this grid.
      Returns:
        The horizontal padding.

    - #### getPaddingY

          public java.lang.Float getPaddingY()

      Returns the vertical padding of this grid.
      Returns:
        The vertical padding.

    - #### getPadding

          public java.lang.Float getPadding()

      Returns the space between the elements of the grid.
      Specified by:
        `getPadding` in interface `RGrid`
      Returns:
        The padding.

    - #### getWidth

          public java.lang.Float getWidth()

      Description copied from interface: `RGrid`
      Returns the width of the element at the given index.
      Specified by:
        `getWidth` in interface `RGrid`
      Returns:
        The width.

    - #### getHeight

          public java.lang.Float getHeight()

      Description copied from interface: `RGrid`
      Returns the current height of the grid.
      Specified by:
        `getHeight` in interface `RGrid`
      Returns:
        The height.

    - #### getX

          public java.lang.Float getX()

      Description copied from interface: `RGrid`
      Returns the current x-position of the grid.
      Specified by:
        `getX` in interface `RGrid`
      Returns:
        The x-position.

    - #### getY

          public java.lang.Float getY()

      Description copied from interface: `RGrid`
      Returns the current y-position of the grid.
      Specified by:
        `getY` in interface `RGrid`
      Returns:
        The y-position.

    - #### getRowX

          public java.lang.Float getRowX(java.lang.Integer rowIndex)

      Returns the x-location of the row with a given row index.
      Parameters:
        `rowIndex` - The row index [0, rows()].
      Returns:
        The x-location of the row.

    - #### getRowY

          public java.lang.Float getRowY(java.lang.Integer rowIndex)

      Returns the y-location of the row with a given row index.
      Parameters:
        `rowIndex` - The row index [0, rows()].
      Returns:
        The y-location of the row.

    - #### getColumnX

          public java.lang.Float getColumnX(java.lang.Integer columnIndex)

      Returns the x-location of the column with a given column index.
      Parameters:
        `columnIndex` - The columnIndex index [0, columns()].
      Returns:
        The x-location of the row.

    - #### getColumnY

          public java.lang.Float getColumnY(java.lang.Integer columnIndex)

      Returns the y-location of the column with a given column index.
      Parameters:
        `columnIndex` - The columnIndex index [0, columns()].
      Returns:
        The y-location of the row.

    - #### getX

          public java.lang.Float getX(java.lang.Integer index)

      Description copied from interface: `RGrid`
      Returns the x-position of the element at the given index. index should be in the range of this grid [0, myGrid.size()], otherwise the call of this function might produce strange results or will produce an ArrayIndexOutOfBoundsException. Usage:

           for (int i = 0; i < myGrid.size(); i++) {
                          float x = myGrid.getX(i);
                          float y = myGrid.getY(i):
           }

      Specified by:
        `getX` in interface `RGrid`
      Parameters:
        `index` - The index of the element.
      Returns:
        The x-position of the element.

    - #### getY

          public java.lang.Float getY(java.lang.Integer index)

      Description copied from interface: `RGrid`
      Returns the y-position of the element at the given index. index should be in the range of this grid [0, myGrid.size()], otherwise the call of this function might produce strange results or will produce an ArrayIndexOutOfBoundsException. Usage:

           for (int i = 0; i < myGrid.size(); i++) {
                          float x = myGrid.getX(i);
                          float y = myGrid.getY(i):
           }

      Specified by:
        `getY` in interface `RGrid`
      Parameters:
        `index` - The index of the element.
      Returns:
        The y-position of the element.

    - #### getRow

          public java.lang.Integer getRow(java.lang.Integer index)

      Returns the row index [0, rows()] with a given element index.
      Parameters:
        `index` - The index of any element [0, size()].
      Returns:
        The row number of the given element.

    - #### getColumn

          public java.lang.Integer getColumn(int index)

      Returns the column index [0, rows()] with a given element index.
      Parameters:
        `index` - The index of any element [0, size()].
      Returns:
        The column number of the given element.

    - #### isEvenRow

          public boolean isEvenRow(int index)

      Returns if the element with the given index is member of an even row.
      Parameters:
        `index` - The index of the element.
      Returns:
        True, if the element is member of an even row.

    - #### isEvenColumn

          public boolean isEvenColumn(int index)

      Returns if the element with the given index is member of an even column.
      Parameters:
        `index` - The index of the element.
      Returns:
        True, if the element is member of an even column.

    - #### index

          public java.lang.Integer index(java.lang.Integer row,
                                         java.lang.Integer column)

      Returns the element index with given column and row index.
      Parameters:
        `row` - The row index [0, rows()].
        `column` - The column index [0, columns()].
      Returns:
        The index [0, size()].

    - #### cellWidth

          public java.lang.Float cellWidth()

      Returns the width of any element in this grid.
      Returns:
        The width of the element.

    - #### cellHeight

          public java.lang.Float cellHeight()

      Returns the height of any element in this grid.
      Returns:
        The height of the element.

    - #### getWidth

          public java.lang.Float getWidth(java.lang.Integer i)

      Description copied from interface: `RGrid`
      Returns the current width of the grid.
      Specified by:
        `getWidth` in interface `RGrid`
      Parameters:
        `i` - The index of the element.
      Returns:
        The width.

    - #### getHeight

          public java.lang.Float getHeight(java.lang.Integer i)

      Description copied from interface: `RGrid`
      Returns the current height of the grid.
      Specified by:
        `getHeight` in interface `RGrid`
      Parameters:
        `i` - The index of the element.
      Returns:
        The height.