# Class LayeredLayout.LayeredLayoutConstraint

java.lang.Object
com.codename1.ui.layouts.LayeredLayout.LayeredLayoutConstraint

Enclosing class:
  `LayeredLayout`

public class LayeredLayout.LayeredLayoutConstraint extends Object
A class that encapsulates the insets for a component in layered layout.

- ## Nested Class Summary

  Nested Classes
  Modifier and Type
  Class
  Description
  `class`
  `LayeredLayout.LayeredLayoutConstraint.Inset`
  Encapsulates an inset.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `LayeredLayoutConstraint()`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `LayeredLayout.LayeredLayoutConstraint.Inset`
  `bottom()`
  Gets the bottom inset.
  `LayeredLayout.LayeredLayoutConstraint`
  `constraint()`
  Gets the constraint itself.
  `LayeredLayout.LayeredLayoutConstraint`
  `copy()`
  Makes a full copy of this inset.
  `LayeredLayout.LayeredLayoutConstraint`
  `copyTo(LayeredLayout.LayeredLayoutConstraint dest)`
  Copies the settings of this constraint into another constraint.
  `boolean`
  `dependsOn(Component cmp)`
  Checks to see if this constraint has the given component in its set of dependencies.
  `LayeredLayout.LayeredLayoutConstraint`
  `fixDependencies(Container parent)`
  Recursively fixes all dependencies so that they are contained inside the provided parent.
  `Set<Component>`
  `getDependencies()`
  Gets the dependencies (i.e. recursively gets all reference components).
  `Set<Component>`
  `getDependencies(Set<Component> deps)`
  Gets the dependencies (i.e. recursively gets all reference components).
  `Collection<LayeredLayout.LayeredLayoutConstraint.Inset>`
  `getFixedInsets()`
  Gets the set of insets on this constraint that are fixed.
  `Collection<LayeredLayout.LayeredLayoutConstraint.Inset>`
  `getFlexibleInsets()`
  Gets the set of insets in this constraint that are flexible.
  `LayeredLayout.LayeredLayoutConstraint.Inset`
  `getInset(int inset)`
  Gets the inset for a particular side.
  `String`
  `getInsetsAsString(boolean withLabels)`
  Gets the insets of this constraint as a string.
  `float`
  `getPercentInsetAnchorHorizontal()`

  ###### Returns

  `float`
  `getPercentInsetAnchorVertical()`

  ###### Returns

  `Rectangle`
  `getReferenceBox(Container parent)`
  Returns a reference box within which insets of the given component are calculated.
  `Rectangle`
  `getReferenceBox(Container parent, Component cmp)`
  Returns a reference box within which insets of the given component are calculated.
  `Rectangle`
  `getReferenceBox(Container parent, Component cmp2, Rectangle box)`
  Returns a reference box within which insets of the given component are calculated.
  `Rectangle`
  `getReferenceBox(Container parent, Rectangle box)`
  Returns a reference box within which insets of the given component are calculated.
  `String`
  `getReferenceComponentIndicesAsString(Container parent, boolean withLabels)`
  Gets the reference component indexes within the provided parent container as a string.
  `String`
  `getReferencePositionsAsString(boolean withLabels)`
  Gets the reference positions of this constraint as a string.
  `boolean`
  `hasCircularDependency(Component start)`
  Checks to see if this constraint has any circular dependencies.
  `LayeredLayout.LayeredLayoutConstraint.Inset`
  `left()`
  Gets the left inset.
  `LayeredLayout.LayeredLayoutConstraint.Inset`
  `right()`
  Gets the right inset.
  `LayeredLayout.LayeredLayoutConstraint`
  `setInsets(String insetStr)`
  Sets the insets for this constraint as a string.
  `LayeredLayout.LayeredLayoutConstraint`
  `setPercentInsetAnchorHorizontal(float anchor)`
  Sets the anchor used for left and right percentage insets.
  `LayeredLayout.LayeredLayoutConstraint`
  `setPercentInsetAnchorVertical(float anchor)`
  Sets the anchor used for top and bottom percentage insets.
  `LayeredLayout.LayeredLayoutConstraint`
  `setReferenceComponentIndices(Container parent, String indices)`
  Sets the reference components of the insets of this constraint as indices of the provided parent container.
  `LayeredLayout.LayeredLayoutConstraint`
  `setReferenceComponents(Component... refs)`
  Sets the reference components for the constraint.
  `LayeredLayout.LayeredLayoutConstraint`
  `setReferencePositions(float... p)`
  Sets the reference positions for the constraint.
  `LayeredLayout.LayeredLayoutConstraint`
  `setReferencePositions(String positionsStr)`
  Sets the reference component positions for this constraint from a string.
  `LayeredLayout.LayeredLayoutConstraint.Inset`
  `top()`
  Gets the top inset
  `String`
  `toString()`
  Gets the insets as a string.
  `LayeredLayout.LayeredLayoutConstraint`
  `translateMM(float x, float y, boolean preferMM, Container parent)`
  Shifts the constraint by the specified number of millimetres while maintaining the same units.
  `LayeredLayout.LayeredLayoutConstraint`
  `translatePixels(int x, int y, boolean preferMM, Container parent)`
  Shifts the constraint by the specified number of pixels while maintaining the same units.

  ### Methods inherited from class Object

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

- ## Constructor Details

  - ### LayeredLayoutConstraint

    public LayeredLayoutConstraint()

- ## Method Details

  - ### toString

    public String toString()
    Gets the insets as a string.
    Overrides:
      `toString` in class `Object`

  - ### fixDependencies

    public LayeredLayout.LayeredLayoutConstraint fixDependencies(Container parent)

    Recursively fixes all dependencies so that they are contained inside the provided parent. A dependency is a "referenceComponent".

    ###### Parameters

    - `parent`: The parent container within which all dependencies should reside.

    ###### Returns

    Self for chaining.

    ###### See also

    - #setReferenceComponents(com.codename1.ui.Component...)

  - ### hasCircularDependency

    public boolean hasCircularDependency(Component start)

    Checks to see if this constraint has any circular dependencies. E.g. Component A has an inset that has Component B as a reference, which has an inset that depends on Component A.

    ###### Parameters

    - `start`: The start component to check.

    ###### Returns

    True this forms a circular dependency.

  - ### getInset

    public LayeredLayout.LayeredLayoutConstraint.Inset getInset(int inset)

    Gets the inset for a particular side.

    ###### Parameters

    - `inset`: @param inset One of `Component#TOP`, `Component#BOTTOM`, `Component#LEFT` or `Component#RIGHT`.

    ###### Returns

    The inset.

  - ### copy

    public LayeredLayout.LayeredLayoutConstraint copy()
    Makes a full copy of this inset.

  - ### copyTo

    public LayeredLayout.LayeredLayoutConstraint copyTo(LayeredLayout.LayeredLayoutConstraint dest)

    Copies the settings of this constraint into another constraint.

    ###### Parameters

    - `dest`: The inset to copy to.

    ###### Returns

    Self for chaining.

  - ### getReferenceBox

    public Rectangle getReferenceBox(Container parent, Rectangle box)

    Returns a reference box within which insets of the given component are calculated. If `cmp` has no reference components in any of its insets, then the resulting box will just bee the inner box of the parent (e.g. the parent's inner bounds.

    ###### Parameters

    - `parent`: The parent container.

    - `parent`

    - `box`: An out parameter. This will store the bounds of the box.

    ###### Returns

    The reference box. (This will be the same object that is passed in the box parameter.

  - ### getReferenceBox

    public Rectangle getReferenceBox(Container parent, Component cmp2, Rectangle box)

    Returns a reference box within which insets of the given component are calculated. If `cmp` has no reference components in any of its insets, then the resulting box will just bee the inner box of the parent (e.g. the parent's inner bounds.

    ###### Parameters

    - `parent`: The parent container.

    - `cmp`: The component whose reference box we are obtaining. Not used. May be null.

    - `box`: An out parameter. This will store the bounds of the box.

    ###### Returns

    The reference box. (This will be the same object that is passed in the box parameter.

    ###### Deprecated

    Use `com.codename1.ui.geom.Rectangle)` instead.

  - ### getReferenceBox

    public Rectangle getReferenceBox(Container parent, Component cmp)

    Returns a reference box within which insets of the given component are calculated. If `cmp` has no reference components in any of its insets, then the resulting box will just bee the inner box of the parent (e.g. the parent's inner bounds.

    ###### Parameters

    - `parent`: The parent container.

    - `cmp`: The component whose reference box we are obtaining.

    ###### Returns

    The reference box.

    ###### Deprecated

    Use `getReferenceBox(com.codename1.ui.Container)`.

  - ### getReferenceBox

    public Rectangle getReferenceBox(Container parent)

    Returns a reference box within which insets of the given component are calculated. If `cmp` has no reference components in any of its insets, then the resulting box will just bee the inner box of the parent (e.g. the parent's inner bounds.

    ###### Parameters

    - `parent`: The parent container.

    ###### Returns

    The reference box.

  - ### translatePixels

    public LayeredLayout.LayeredLayoutConstraint translatePixels(int x, int y, boolean preferMM, Container parent)

    Shifts the constraint by the specified number of pixels while maintaining the same units. This is used mainly in the GUI builder to facilitate dragging and resizing of the component.

    ###### Parameters

    - `x`: The number of pixels that the insets should be shifted on the x axis.

    - `y`: The number of pixels that the insets should be shifted on the y axis.

    - `preferMM`: @param preferMM If an inset needs to be switched from flexible to fixed, then this indicates where it will be changed to millimetres or pixels. true for millimetres.

    - `parent`: The parent container in which calculations should be performed.

    ###### Returns

    Self for chaining.

    ###### See also

    - #translateMM(float, float, boolean, com.codename1.ui.Container)

  - ### translateMM

    public LayeredLayout.LayeredLayoutConstraint translateMM(float x, float y, boolean preferMM, Container parent)

    Shifts the constraint by the specified number of millimetres while maintaining the same units. This is used mainly in the GUI builder to facilitate dragging and resizing of the component.

    ###### Parameters

    - `x`: The number of pixels that the insets should be shifted on the x axis.

    - `y`: The number of pixels that the insets should be shifted on the y axis.

    - `preferMM`: @param preferMM If an inset needs to be switched from flexible to fixed, then this indicates where it will be changed to millimetres or pixels. true for millimetres.

    - `parent`: The parent container in which calculations should be performed.

    ###### Returns

    Self for chaining.

    ###### See also

    - #translatePixels(int, int, boolean, com.codename1.ui.Container)

  - ### getFixedInsets

    public Collection<LayeredLayout.LayeredLayoutConstraint.Inset> getFixedInsets()
    Gets the set of insets on this constraint that are fixed. An inset is considered fixed if it's unit is NOT `#UNIT_AUTO`.

  - ### getFlexibleInsets

    public Collection<LayeredLayout.LayeredLayoutConstraint.Inset> getFlexibleInsets()
    Gets the set of insets in this constraint that are flexible. An inset is considered flexible if it's unit is `#UNIT_AUTO`.

  - ### getReferencePositionsAsString

    public String getReferencePositionsAsString(boolean withLabels)

    Gets the reference positions of this constraint as a string.

    ###### Parameters

    - `withLabels`: @param withLabels True to return the string in CSS format: e.g. `"top:1.0; right:0; bottom:1.0; left:1.0"` false to return as a space-delimited string of inset reference positions in the order "top right bottom left". E.g. "1.0 0 1.0 1.0"

    ###### Returns

    The reference positions as a string.

  - ### setReferencePositions

    public LayeredLayout.LayeredLayoutConstraint setReferencePositions(String positionsStr)

    Sets the reference component positions for this constraint from a string. The string format may be either using labels following the same output format of getReferencePositionsAsString(true) or as a space-delimited string (e.g. getReferencePositionsAsString(false). When using the label format, you may provide one or more inset values in the string. E.g. the following are all acceptable:

    - top:1.0; left:0; right:0; bottom:1.0

    - left:0.5

    - left:1.0; right:0.5

    If you provide the positions as a space-delimited string, then they are expected to follow the same format as is used in CSS for providing margin. To summarize:

    `//Apply to all four sides 1.0

    //vertical | horizontal 1.0 0

    // top | horizontal | bottom 1.0 0.0 0.5

    // top | right | bottom | left 1.0 1.0 1.0 1.0`

    Interpretation of Reference Positions:

    When an inset includes a reference component, that means that the inset is "anchored" to that reference component. I.e. An inset of 1mm is measured 1mm from the outer edge of the reference component. By default it chooses the edge of on the same side as the inset. So if this is a "left" inset, then it will measure against the "left" outer edge of the reference component. This is the meaning of a 0 value for the associated reference positions.

    A reference position of 1.0 will start measuring from the opposite edge. So for a "left" inset, it will measure from the "right" outer edge of the reference component. You can choose any real value for the reference position, and it will cause the measurement to be scaled accordingly. E.g. 0.5. would measure from the center point of the reference component.

    ###### Parameters

    - `positionsStr`: The reference positions.

    ###### Returns

    Self for chaining.

  - ### getReferenceComponentIndicesAsString

    public String getReferenceComponentIndicesAsString(Container parent, boolean withLabels)

    Gets the reference component indexes within the provided parent container as a string. If an inset doesn't have a reference component, then the corresponding index will be -1.

    Use the withLabels parameter to choose whether to include labels with the indices or not. E.g:

    `String indices = getReferenceComponentIndicesAsString(parent, true); // Would return something like // "top:-1; right:2; bottom:-1; left: 0"

    indices = getReferenceComponentIndicesAsString(parent, false); // Would return something like: // "-1 2 -1 0" (i.e. Top Right Bottom Left)

    // Interpretation: // Top inset has no reference component // Right inset has component with index 2 (i.e. parent.getComponentIndex(rightReferenceComponent) == 2) // Bottom inset has no reference component // Left inset has component with index 0 as a reference component.`

    ###### Parameters

    - `parent`

    - `withLabels`

  - ### setReferenceComponentIndices

    public LayeredLayout.LayeredLayoutConstraint setReferenceComponentIndices(Container parent, String indices)

    Sets the reference components of the insets of this constraint as indices of the provided parent container.

    ###### Parameters

    - `parent`: The parent container whose children are to be used as reference components.

    - `indices`: @param indices The indices to set as the reference components.

    The string format may be either using labels following the same output format of cnst.getReferenceComponentIndicesAsString(true) or as a space-delimited string (e.g. cnst.getReferenceComponentIndicesAsString(false). When using the label format, you may provide one or more inset values in the string. E.g. the following are all acceptable:

    - top:-1; left:0; right:0; bottom:1

    - left:1

    - left:10; right:-1

    If you provide the positions as a space-delimited string, then they are expected to follow the same format as is used in CSS for providing margin. To summarize:

    `//Set component at index 0 as reference for all 4 insets. 0

    //vertical insets use component index 2 | horizontal insets use component index 1 2 1

    // top | horizontal | bottom -1 3 10

    // top | right | bottom | left -1 -1 -1 -1`

    Note: An index of -1 means that the corresponding inset has no reference component.

  - ### getInsetsAsString

    public String getInsetsAsString(boolean withLabels)

    Gets the insets of this constraint as a string. If withLabels is true, then it will return a string of the format:

    top:2mm; right:0; bottom:10%; left:auto

    If withLabels is false then it will return a space-delimited string with the inset values ordered "top right bottom left" (the same as for CSS margins) order.

    ###### Parameters

    - `withLabels`

  - ### setReferenceComponents

    public LayeredLayout.LayeredLayoutConstraint setReferenceComponents(Component... refs)

    Sets the reference components for the constraint.

    ###### Parameters

    - `refs`: @param refs May contain 1, 2, 3, or 4 values. If only 1 value is passed, then it is set on all 4 insets. If two values are passed, then the first is set on the top and bottom insets, and the 2nd is set on the left and right insets (i.e. vertical | horizontal). If 3 values are passed, then, they are used for top, horizontal, and bottom. If 4 values are passed, then they are used for top, right, bottom, left (in that order).

    ###### Returns

    Self for chaining.

  - ### setReferencePositions

    public LayeredLayout.LayeredLayoutConstraint setReferencePositions(float... p)

    Sets the reference positions for the constraint.

    Interpretation of Reference Positions:

    When an inset includes a reference component, that means that the inset is "anchored" to that reference component. I.e. An inset of 1mm is measured 1mm from the outer edge of the reference component. By default it chooses the edge of on the same side as the inset. So if this is a "left" inset, then it will measure against the "left" outer edge of the reference component. This is the meaning of a 0 value for the associated reference positions.

    A reference position of 1.0 will start measuring from the opposite edge. So for a "left" inset, it will measure from the "right" outer edge of the reference component. You can choose any real value for the reference position, and it will cause the measurement to be scaled accordingly. E.g. 0.5. would measure from the center point of the reference component.

    ###### Parameters

    - `p`: @param p May contain 1, 2, 3, or 4 values. If only 1 value is passed, then it is set on all 4 insets. If two values are passed, then the first is set on the top and bottom insets, and the 2nd is set on the left and right insets (i.e. vertical | horizontal). If 3 values are passed, then, they are used for top, horizontal, and bottom. If 4 values are passed, then they are used for top, right, bottom, left (in that order).

    ###### Returns

    Self for chaining.

  - ### setInsets

    public LayeredLayout.LayeredLayoutConstraint setInsets(String insetStr)

    Sets the insets for this constraint as a string. The string may include labels or it may be a space delimited string of values with "top right bottom left" order.

    If providing as a space-delimited string of inset values, then you can provide 1, 2, 3, or 4 values. If only 1 value is passed, then it is set on all 4 insets. If two values are passed, then the first is set on the top and bottom insets, and the 2nd is set on the left and right insets (i.e. vertical | horizontal). If 3 values are passed, then, they are used for top, horizontal, and bottom. If 4 values are passed, then they are used for top, right, bottom, left (in that order).

    Example Inputs

    - "0 0 0 0" = all 4 insets are zero pixels

    - "0 1mm" = Vertical insets are zero. Horizontal insets are 1mm

    - "10% auto 20%" = Top inset is 10%. Horizontal insets are flexible. Bottom is 20%

    - "1mm 2mm 3mm 4mm" = Top=1mm, Right=2mm, Bottom=3mm, Left=4mm

    ###### Parameters

    - `insetStr`

    ###### Returns

    Self for chaining.

  - ### left

    public LayeredLayout.LayeredLayoutConstraint.Inset left()

    Gets the left inset.

    ###### Returns

    The left inset

  - ### right

    public LayeredLayout.LayeredLayoutConstraint.Inset right()

    Gets the right inset.

    ###### Returns

    The right inset.

  - ### top

    public LayeredLayout.LayeredLayoutConstraint.Inset top()

    Gets the top inset

    ###### Returns

    The top inset

  - ### bottom

    public LayeredLayout.LayeredLayoutConstraint.Inset bottom()

    Gets the bottom inset.

    ###### Returns

    The bottom inset

  - ### getPercentInsetAnchorHorizontal

    public float getPercentInsetAnchorHorizontal()

    ###### Returns

    anchor used for left and right percentage insets

  - ### setPercentInsetAnchorHorizontal

    public LayeredLayout.LayeredLayoutConstraint setPercentInsetAnchorHorizontal(float anchor)

    Sets the anchor used for left and right percentage insets. An anchor of 0 points to the component's edge which is on that side the inset refers to (e.g. in case of the left inset the left edge). An anchor of 1 points to the edge on the opposite side. By default 0 is used as anchor.

    ###### Parameters

    - `anchor`

    ###### Returns

    Self for chaining

  - ### getPercentInsetAnchorVertical

    public float getPercentInsetAnchorVertical()

    ###### Returns

    anchor used for top and bottom percentage insets

  - ### setPercentInsetAnchorVertical

    public LayeredLayout.LayeredLayoutConstraint setPercentInsetAnchorVertical(float anchor)

    Sets the anchor used for top and bottom percentage insets. An anchor of 0 points to the component's edge which is on that side the inset refers to (e.g. in case of the top inset the top edge). An anchor of 1 points to the edge on the opposite side. By default 0 is used as anchor.

    ###### Parameters

    - `anchor`

    ###### Returns

    Self for chaining

  - ### constraint

    public LayeredLayout.LayeredLayoutConstraint constraint()
    Gets the constraint itself.

  - ### getDependencies

    public Set<Component> getDependencies(Set<Component> deps)

    Gets the dependencies (i.e. recursively gets all reference components).

    ###### Parameters

    - `deps`: A set to add the dependencies to. (An "out" parameter).

    ###### Returns

    The set of dependencies. Same as dep parameter.

  - ### getDependencies

    public Set<Component> getDependencies()

    Gets the dependencies (i.e. recursively gets all reference components).

    ###### Returns

    The set of dependencies.

  - ### dependsOn

    public boolean dependsOn(Component cmp)

    Checks to see if this constraint has the given component in its set of dependencies.

    ###### Parameters

    - `cmp`: The component to check.

    ###### Returns

    Returns:
      True if cmp is a reference component of some inset in this constraint (recursively).