Class LayeredLayout.LayeredLayoutConstraint
- Enclosing class:
LayeredLayout
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionclassEncapsulates an inset. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbottom()Gets the bottom inset.Gets the constraint itself.copy()Makes a full copy of this inset.Copies the settings of this constraint into another constraint.booleanChecks to see if this constraint has the given component in its set of dependencies.fixDependencies(Container parent) Recursively fixes all dependencies so that they are contained inside the provided parent.Gets the dependencies (i.e. recursively gets all reference components).getDependencies(Set<Component> deps) Gets the dependencies (i.e. recursively gets all reference components).Gets the set of insets on this constraint that are fixed.Gets the set of insets in this constraint that are flexible.getInset(int inset) Gets the inset for a particular side.getInsetsAsString(boolean withLabels) Gets the insets of this constraint as a string.floatReturns
floatReturns
getReferenceBox(Container parent) Returns a reference box within which insets of the given component are calculated.getReferenceBox(Container parent, Component cmp) Returns a reference box within which insets of the given component are calculated.getReferenceBox(Container parent, Component cmp2, Rectangle box) Returns a reference box within which insets of the given component are calculated.getReferenceBox(Container parent, Rectangle box) Returns a reference box within which insets of the given component are calculated.getReferenceComponentIndicesAsString(Container parent, boolean withLabels) Gets the reference component indexes within the provided parent container as a string.getReferencePositionsAsString(boolean withLabels) Gets the reference positions of this constraint as a string.booleanhasCircularDependency(Component start) Checks to see if this constraint has any circular dependencies.left()Gets the left inset.right()Gets the right inset.Sets the insets for this constraint as a string.setPercentInsetAnchorHorizontal(float anchor) Sets the anchor used for left and right percentage insets.setPercentInsetAnchorVertical(float anchor) Sets the anchor used for top and bottom percentage insets.setReferenceComponentIndices(Container parent, String indices) Sets the reference components of the insets of this constraint as indices of the provided parent container.setReferenceComponents(Component... refs) Sets the reference components for the constraint.setReferencePositions(float... p) Sets the reference positions for the constraint.setReferencePositions(String positionsStr) Sets the reference component positions for this constraint from a string.top()Gets the top insettoString()Gets the insets as a string.translateMM(float x, float y, boolean preferMM, Container parent) Shifts the constraint by the specified number of millimetres while maintaining the same units.translatePixels(int x, int y, boolean preferMM, Container parent) Shifts the constraint by the specified number of pixels while maintaining the same units.
-
Constructor Details
-
LayeredLayoutConstraint
public LayeredLayoutConstraint()
-
-
Method Details
-
toString
-
fixDependencies
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
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
Gets the inset for a particular side.
Parameters
inset: @param inset One ofComponent#TOP,Component#BOTTOM,Component#LEFTorComponent#RIGHT.
Returns
The inset.
-
copy
Makes a full copy of this inset. -
copyTo
Copies the settings of this constraint into another constraint.
Parameters
dest: The inset to copy to.
Returns
Self for chaining.
-
getReferenceBox
Returns a reference box within which insets of the given component are calculated. If
cmphas 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
Returns a reference box within which insets of the given component are calculated. If
cmphas 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
Returns a reference box within which insets of the given component are calculated. If
cmphas 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
-
-
getReferenceBox
Returns a reference box within which insets of the given component are calculated. If
cmphas 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
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
Gets the set of insets in this constraint that are flexible. An inset is considered flexible if it's unit is#UNIT_AUTO. -
getReferencePositionsAsString
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
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
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
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
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
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
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
Gets the left inset.
Returns
The left inset
-
right
Gets the right inset.
Returns
The right inset.
-
top
Gets the top inset
Returns
The top inset
-
bottom
Gets the bottom inset.
Returns
The bottom inset
-
getPercentInsetAnchorHorizontal
public float getPercentInsetAnchorHorizontal()Returns
anchor used for left and right percentage insets
-
setPercentInsetAnchorHorizontal
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
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
Gets the constraint itself. -
getDependencies
-
getDependencies
-
dependsOn
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).
-