public class LayeredLayout.LayeredLayoutConstraint

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

Nested types

class LayeredLayout.LayeredLayoutConstraint.InsetEncapsulates an inset.

Constructors

public LayeredLayoutConstraint()

Methods

public String toString()Gets the insets as a string.
public LayeredLayout.LayeredLayoutConstraint fixDependencies(Container parent)Recursively fixes all dependencies so that they are contained inside the provided parent.
public boolean hasCircularDependency(Component start)Checks to see if this constraint has any circular dependencies.
public LayeredLayout.LayeredLayoutConstraint.Inset getInset(int inset)Gets the inset for a particular side.
public LayeredLayout.LayeredLayoutConstraint copy()Makes a full copy of this inset.
public LayeredLayout.LayeredLayoutConstraint copyTo(LayeredLayout.LayeredLayoutConstraint dest)Copies the settings of this constraint into another constraint.
public Rectangle getReferenceBox(Container parent, Rectangle box)Returns a reference box within which insets of the given component are calculated.
public Rectangle getReferenceBox(Container parent, Component cmp2, Rectangle box)Deprecated Returns a reference box within which insets of the given component are calculated.
public Rectangle getReferenceBox(Container parent, Component cmp)Deprecated Returns a reference box within which insets of the given component are calculated.
public Rectangle getReferenceBox(Container parent)Returns a reference box within which insets of the given component are calculated.
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.
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.
public Collection<LayeredLayout.LayeredLayoutConstraint.Inset> getFixedInsets()Gets the set of insets on this constraint that are fixed.
public Collection<LayeredLayout.LayeredLayoutConstraint.Inset> getFlexibleInsets()Gets the set of insets in this constraint that are flexible.
public String getReferencePositionsAsString(boolean withLabels)Gets the reference positions of this constraint as a string.
public LayeredLayout.LayeredLayoutConstraint setReferencePositions(String positionsStr)Sets the reference component positions for this constraint from a string.
public String getReferenceComponentIndicesAsString(Container parent, boolean withLabels)Gets the reference component indexes within the provided parent container as a string.
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.
public String getInsetsAsString(boolean withLabels)Gets the insets of this constraint as a string.
public LayeredLayout.LayeredLayoutConstraint setReferenceComponents(Component... refs)Sets the reference components for the constraint.
public LayeredLayout.LayeredLayoutConstraint setReferencePositions(float... p)Sets the reference positions for the constraint.
public LayeredLayout.LayeredLayoutConstraint setInsets(String insetStr)Sets the insets for this constraint as a string.
public LayeredLayout.LayeredLayoutConstraint.Inset left()Gets the left inset.
public LayeredLayout.LayeredLayoutConstraint.Inset right()Gets the right inset.
public LayeredLayout.LayeredLayoutConstraint.Inset top()Gets the top inset
public LayeredLayout.LayeredLayoutConstraint.Inset bottom()Gets the bottom inset.
public float getPercentInsetAnchorHorizontal()
public LayeredLayout.LayeredLayoutConstraint setPercentInsetAnchorHorizontal(float anchor)Sets the anchor used for left and right percentage insets.
public float getPercentInsetAnchorVertical()
public LayeredLayout.LayeredLayoutConstraint setPercentInsetAnchorVertical(float anchor)Sets the anchor used for top and bottom percentage insets.
public LayeredLayout.LayeredLayoutConstraint constraint()Gets the constraint itself.
public Set<Component> getDependencies(Set<Component> deps)Gets the dependencies (i.e. recursively gets all reference components).
public Set<Component> getDependencies()Gets the dependencies (i.e. recursively gets all reference components).
public boolean dependsOn(Component cmp)Checks to see if this constraint has the given component in its set of dependencies.

Inherited methods

Constructor details

LayeredLayoutConstraint

public LayeredLayoutConstraint()

Method details

toString

public String toString()
Gets the insets as a string.

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 Container
The parent container within which all dependencies should reside.

Returns

Self for chaining.

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 Component
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 int
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 LayeredLayout.LayeredLayoutConstraint
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 Container
The parent container.
box Rectangle
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)
Deprecated. Use com.codename1.ui.geom.Rectangle) instead.
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 Container
The parent container.
cmp2 Component
Not documented.
box Rectangle
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 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 Container
The parent container.
cmp Component
The component whose reference box we are obtaining.

Returns

The reference box.

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 Container
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 int
The number of pixels that the insets should be shifted on the x axis.
y int
The number of pixels that the insets should be shifted on the y axis.
preferMM boolean
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 Container
The parent container in which calculations should be performed.

Returns

Self for chaining.

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 float
The number of pixels that the insets should be shifted on the x axis.
y float
The number of pixels that the insets should be shifted on the y axis.
preferMM boolean
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 Container
The parent container in which calculations should be performed.

Returns

Self for chaining.

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 boolean
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 String
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.`

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 Container
The parent container whose children are to be used as reference components.
indices String

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:

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.

setReferenceComponents

public LayeredLayout.LayeredLayoutConstraint setReferenceComponents(Component... refs)
Sets the reference components for the constraint.

Parameters

refs Component...
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 float...
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

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.

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.

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 Set<Component>
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 Component
The component to check.

Returns

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