Package ej.mwt.util

## Class Alignment

- java.lang.Object
- - ej.mwt.util.Alignment

-     public class Alignment
      extends Object

  Provides constants and utility methods in order to position a graphical object considering its alignment within an area or with an anchor point.

- - ### Field Summary

    Fields
    Modifier and Type | Field | Description
    --- | --- | ---
    `static int` | `BOTTOM` | Constant for positioning on the bottom.
    `static int` | `HCENTER` | Constant for centering horizontally.
    `static int` | `LEFT` | Constant for positioning on the left.
    `static int` | `RIGHT` | Constant for positioning on the right.
    `static int` | `TOP` | Constant for positioning on the top.
    `static int` | `VCENTER` | Constant for centering vertically.

  - ### Constructor Summary

    Constructors
    Constructor | Description
    --- | ---
    `Alignment()` |

  - ### Method Summary

    All Methods Static Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `static boolean` | `checkHorizontalAlignment​(int horizontalAlignment)` | Checks whether the given value represents a valid horizontal alignment.
    `static boolean` | `checkVerticalAlignment​(int verticalAlignment)` | Checks whether the given value represents a valid vertical alignment.
    `static int` | `computeLeftX​(int width, int anchorX, int horizontalAlignment)` | Computes the x coordinate of the left edge of an object aligned on an anchor point.
    `static int` | `computeLeftX​(int width, int areaX, int areaWidth, int horizontalAlignment)` | Computes the x coordinate of the left edge of an object aligned in an area.
    `static int` | `computeTopY​(int height, int anchorY, int verticalAlignment)` | Computes the y coordinate of the top edge of an object aligned on an anchor point.
    `static int` | `computeTopY​(int height, int areaY, int areaHeight, int verticalAlignment)` | Computes the y coordinate of the top edge of an object aligned in an area.
    `static void` | `validateHorizontalAlignment​(int horizontalAlignment)` | Validates that the given value represents a valid horizontal alignment.
    `static void` | `validateVerticalAlignment​(int verticalAlignment)` | Validates that the given value represents a valid vertical alignment.

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

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

- - ### Field Detail

    - #### LEFT

          public static final int LEFT

      Constant for positioning on the left.
      See Also:
        Constant Field Values

    - #### HCENTER

          public static final int HCENTER

      Constant for centering horizontally.
      See Also:
        Constant Field Values

    - #### RIGHT

          public static final int RIGHT

      Constant for positioning on the right.
      See Also:
        Constant Field Values

    - #### TOP

          public static final int TOP

      Constant for positioning on the top.
      See Also:
        Constant Field Values

    - #### VCENTER

          public static final int VCENTER

      Constant for centering vertically.
      See Also:
        Constant Field Values

    - #### BOTTOM

          public static final int BOTTOM

      Constant for positioning on the bottom.
      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### Alignment

          public Alignment()

  - ### Method Detail

    - #### validateHorizontalAlignment

          public static void validateHorizontalAlignment​(int horizontalAlignment)

      Validates that the given value represents a valid horizontal alignment.

      This method is equivalent to `checkHorizontalAlignment(int)` except that it throws an exception rather than return a boolean.

      Parameters:
        `horizontalAlignment` - the horizontal alignment to check.
      Throws:
        `IllegalArgumentException` - if the given horizontal alignment is not valid.

    - #### validateVerticalAlignment

          public static void validateVerticalAlignment​(int verticalAlignment)

      Validates that the given value represents a valid vertical alignment.

      This method is equivalent to `checkVerticalAlignment(int)` except that it throws an exception rather than return a boolean.

      Parameters:
        `verticalAlignment` - the vertical alignment to check.
      Throws:
        `IllegalArgumentException` - if the given vertical alignment is not valid.

    - #### checkHorizontalAlignment

          public static boolean checkHorizontalAlignment​(int horizontalAlignment)

      Checks whether the given value represents a valid horizontal alignment.

      A value represents a valid horizontal alignment if it is equal to either `LEFT`, `HCENTER` or `RIGHT`.

      Parameters:
        `horizontalAlignment` - the horizontal alignment to check.
      Returns:
        `true` if the given horizontal alignment is valid, `false` otherwise.

    - #### checkVerticalAlignment

          public static boolean checkVerticalAlignment​(int verticalAlignment)

      Checks whether the given value represents a valid vertical alignment.

      A value represents a valid vertical alignment if it is equal to either `TOP`, `VCENTER` or `BOTTOM`.

      Parameters:
        `verticalAlignment` - the vertical alignment to check.
      Returns:
        `true` if the given vertical alignment is valid, `false` otherwise.

    - #### computeLeftX

          public static int computeLeftX​(int width,
                                         int areaX,
                                         int areaWidth,
                                         int horizontalAlignment)

      Computes the x coordinate of the left edge of an object aligned in an area.

      If the horizontal alignment is invalid or not set, the object is aligned on the left.

      Parameters:
        `width` - the object width.
        `areaX` - the area x coordinate.
        `areaWidth` - the area width.
        `horizontalAlignment` - the horizontal alignment.
      Returns:
        the x coordinate of the left of the object.
      See Also:
        `checkHorizontalAlignment(int)`

    - #### computeTopY

          public static int computeTopY​(int height,
                                        int areaY,
                                        int areaHeight,
                                        int verticalAlignment)

      Computes the y coordinate of the top edge of an object aligned in an area.

      If the vertical alignment is invalid or not set, the object is aligned on the top.

      Parameters:
        `height` - the object height.
        `areaY` - the area y coordinate.
        `areaHeight` - the area height.
        `verticalAlignment` - the vertical alignment.
      Returns:
        the y coordinate of the top of the object.
      See Also:
        `checkVerticalAlignment(int)`

    - #### computeLeftX

          public static int computeLeftX​(int width,
                                         int anchorX,
                                         int horizontalAlignment)

      Computes the x coordinate of the left edge of an object aligned on an anchor point.

      If the horizontal alignment is invalid, the object is aligned on the left.

      Parameters:
        `width` - the object width.
        `anchorX` - the anchor x coordinate.
        `horizontalAlignment` - the horizontal alignment.
      Returns:
        the x coordinate of the left of the object.

    - #### computeTopY

          public static int computeTopY​(int height,
                                        int anchorY,
                                        int verticalAlignment)

      Computes the y coordinate of the top edge of an object aligned on an anchor point.

      If the vertical alignment is invalid, the object is aligned on the top.

      Parameters:
        `height` - the object height.
        `anchorY` - the anchor y coordinate.
        `verticalAlignment` - the vertical alignment.
      Returns:
        the y coordinate of the top of the object.