de.winterdrache.layout
Interface MSBLayout.MutableConstraints

All Superinterfaces:
MSBLayout.Constraints
All Known Implementing Classes:
MSBLayout.ConstraintsImpl
Enclosing class:
MSBLayout

public static interface MSBLayout.MutableConstraints
extends MSBLayout.Constraints

Extends the (read-only) Constraints interface with methods to modify the constraints.

Every box in an MSBLayout is associated with a Constraints object that controls the sizing and placement behaviour of the box. The methods MSBLayout.add(Component, Constraints), Container.add(Component, Object), hbox(Constraints) and vbox(Constraints) accept Constraints that will be used for the new box. If you do not use one of these methods, MSBLayout will use a ConstraintsFactory to provide an appropriate Constraints object.

Constraints is a read-only interface. The interface MutableConstraints extends Constraints with the corresponding methods for setting constraints. The method MSBLayout.add(Component) for instance returns an object of type MutableConstraints that allows you to change the constraints of the box just added.

A simple implementation of this interface is available as the ConstraintsImpl class.

Author:
Matthias S. Benkmann
See Also:
MSBLayout.ConstraintsImpl, MSBLayout.Constraints

Method Summary
 MSBLayout.MutableConstraints bottom(int bottomMargin)
          Sets the bottom margin and leaves the other margins unchanged.
 MSBLayout.MutableConstraints groups(String groups)
          Takes a comma-separated list of group names (that must not contain spurious whitespace) that will replace the list of groups this box is currently part of.
 MSBLayout.MutableConstraints groups(String[] groups)
          Takes a list of group names that will replace the list of groups this box is currently part of.
 MSBLayout.MutableConstraints halign(float a)
          When this box is contained in a box that has excess blank space, the alignment determines where that blank space will be relative to this box.
 MSBLayout.MutableConstraints hfill(int fill)
          Sets the box's willingness to grow horizontally to fill excess space. 0 means the Box insists on its preferred size. 1 means this Box is willing to grow to its maximum size if required. 2 means the Box is willing to grow beyond its maximum size if there is still too much space after all boxes with willingness == 1 have been grown to their max sizes.
 MSBLayout.MutableConstraints hscale(float scale)
          A box that is part of a Group with tieWidth() uses the group's tied minimum, preferred and maximum widths multiplied by this factor.
 MSBLayout.MutableConstraints hshrink(int weight)
          When boxes are shrunk below their preferred sizes because their container is too small, the weight value determines the relative amount of space this Box will lose.
 MSBLayout.MutableConstraints hweight(int weight)
          When boxes are grown to fill excess space in the parent container, the weight value determines the relative portion of space this Box will get.
 MSBLayout.MutableConstraints left(int leftMargin)
          Sets the left margin and leaves the other margins unchanged.
 MSBLayout.MutableConstraints margin(Insets insets)
          Sets an amount of blank space to be added around the box's content.
 MSBLayout.MutableConstraints margin(int top, int left, int bottom, int right)
          Sets an amount of blank space to be added around the box's content.
 MSBLayout.MutableConstraints padding(Dimension insets)
          Sets an amount of space to be added to the box's minimum, preferred and maximum sizes when doing size computations.
 MSBLayout.MutableConstraints padding(int width, int height)
          Sets an amount of space to be added to the box's minimum, preferred and maximum sizes when doing size computations.
 MSBLayout.MutableConstraints right(int rightMargin)
          Sets the right margin and leaves the other margins unchanged.
 MSBLayout.MutableConstraints setConstraints(MSBLayout.Constraints orig)
          Copies the settings from orig to this MutableConstraints object.
 MSBLayout.MutableConstraints top(int topMargin)
          Sets the top margin and leaves the other margins unchanged.
 MSBLayout.MutableConstraints valign(float a)
          When this box is contained in a box that has excess blank space, the alignment determines where that blank space will be relative to this box.
 MSBLayout.MutableConstraints vfill(int fill)
          Sets the box's willingness to grow vertically to fill excess space. 0 means the Box insists on its preferred size. 1 means this Box is willing to grow to its maximum size if required. 2 means the Box is willing to grow beyond its maximum size if there is still too much space after all boxes with willingness == 1 have been grown to their max sizes.
 MSBLayout.MutableConstraints vscale(float scale)
          A box that is part of a Group with tieHeight() uses the group's tied minimum, preferred and maximum heights multiplied by this factor.
 MSBLayout.MutableConstraints vshrink(int weight)
          When boxes are shrunk below their preferred sizes because their container is too small, the weight value determines the relative amount of space this Box will lose.
 MSBLayout.MutableConstraints vweight(int weight)
          When boxes are grown to fill excess space in the parent container, the weight value determines the relative portion of space this Box will get.
 
Methods inherited from interface de.winterdrache.layout.MSBLayout.Constraints
bottom, groups, halign, hfill, hscale, hshrink, hweight, left, margin, padding, right, top, valign, vfill, vscale, vshrink, vweight
 

Method Detail

groups

MSBLayout.MutableConstraints groups(String groups)
Takes a comma-separated list of group names (that must not contain spurious whitespace) that will replace the list of groups this box is currently part of. null may be passed to remove the box from any groups. Note that passing the empty string will NOT clear the list of groups. The empty string is a legitimate group name.

See Also:
MSBLayout.Constraints.groups(), groups(String[])

groups

MSBLayout.MutableConstraints groups(String[] groups)
Takes a list of group names that will replace the list of groups this box is currently part of. null may be passed to remove the box from any groups.

See Also:
MSBLayout.Constraints.groups(), groups(String)

margin

MSBLayout.MutableConstraints margin(Insets insets)
Sets an amount of blank space to be added around the box's content. The top, left, bottom and right values can be either non-negative pixel values or Gap constants. To set the margins for the different sides individually, you can use the methods top(int), left(int), bottom(int) and right(int).

Returns:
this
See Also:
MSBLayout.Gap, margin(int, int, int, int), MSBLayout.Constraints.margin(), padding(Dimension), top(int), left(int), bottom(int), right(int)

margin

MSBLayout.MutableConstraints margin(int top,
                                    int left,
                                    int bottom,
                                    int right)
Sets an amount of blank space to be added around the box's content. The top, left, bottom and right values can be either non-negative pixel values or Gap constants. To set the margins for the different sides individually, you can use the methods top(int), left(int), bottom(int) and right(int).

Returns:
this
See Also:
MSBLayout.Gap, margin(Insets), MSBLayout.Constraints.margin(), padding(int, int), top(int), left(int), bottom(int), right(int)

left

MSBLayout.MutableConstraints left(int leftMargin)
Sets the left margin and leaves the other margins unchanged. The argument can be either a non-negative pixel value or one of the Gap constants.

Returns:
this
See Also:
MSBLayout.Gap, margin(Insets), margin(int, int, int, int), padding(int, int), MSBLayout.Constraints.left()

right

MSBLayout.MutableConstraints right(int rightMargin)
Sets the right margin and leaves the other margins unchanged. The argument can be either a non-negative pixel value or one of the Gap constants.

Returns:
this
See Also:
MSBLayout.Gap, margin(Insets), margin(int, int, int, int), padding(int, int), MSBLayout.Constraints.right()

top

MSBLayout.MutableConstraints top(int topMargin)
Sets the top margin and leaves the other margins unchanged. The argument can be either a non-negative pixel value or one of the Gap constants.

Returns:
this
See Also:
MSBLayout.Gap, margin(Insets), margin(int, int, int, int), padding(int, int), MSBLayout.Constraints.top()

bottom

MSBLayout.MutableConstraints bottom(int bottomMargin)
Sets the bottom margin and leaves the other margins unchanged. The argument can be either a non-negative pixel value or one of the Gap constants.

Returns:
this
See Also:
MSBLayout.Gap, margin(Insets), margin(int, int, int, int), padding(int, int), MSBLayout.Constraints.bottom()

padding

MSBLayout.MutableConstraints padding(Dimension insets)
Sets an amount of space to be added to the box's minimum, preferred and maximum sizes when doing size computations. The width and height components of the Dimension must be non-negative. Note that padding is very different from a margin. A margin is an empty space around a box. Padding on the other hand grows the box's content. Unlike margins, padding is used rather infrequently.

Returns:
this
See Also:
padding(int, int), MSBLayout.Constraints.padding(), margin(Insets)

padding

MSBLayout.MutableConstraints padding(int width,
                                     int height)
Sets an amount of space to be added to the box's minimum, preferred and maximum sizes when doing size computations. Both width and height must be non-negative. Note that padding is very different from a margin. A margin is an empty space around a box. Padding on the other hand grows the box's content. Unlike margins, padding is used rather infrequently.

Returns:
this
See Also:
padding(Dimension), MSBLayout.Constraints.padding(), margin(int, int, int, int)

hweight

MSBLayout.MutableConstraints hweight(int weight)
When boxes are grown to fill excess space in the parent container, the weight value determines the relative portion of space this Box will get. You can think of this value as specifying how fast the box will grow in relation to other boxes in the same container. A box with twice the hweight() value, will receive twice the space. The value is always > 0 and <= MAX_WEIGHT_SHRINK and can be set independently for horizontal (hweight) and vertical space (vweight). ATTENTION! The weight must be greater than 0. This is different from GridBagLayout where a weight of 0 means that a box will not grow. If you don't want a box to grow, use hfill(int)/ vfill(int).

hshrink(int) plays a similar role when shrinking a box below its preferred width.

Returns:
this
Throws:
IllegalArgumentException - if weight <= 0 or > MAX_WEIGHT_SHRINK.
See Also:
vweight(int), MSBLayout.Constraints.hweight(), hshrink(int)

vweight

MSBLayout.MutableConstraints vweight(int weight)
When boxes are grown to fill excess space in the parent container, the weight value determines the relative portion of space this Box will get. You can think of this value as specifying how fast the box will grow in relation to other boxes in the same container. A box with twice the vweight() value, will receive twice the space. The value is always >0 and <= MAX_WEIGHT_SHRINK and can be set independently for horizontal (hweight) and vertical space (vweight). ATTENTION! The weight must be greater than 0. This is different from GridBagLayout where a weight of 0 means that a box will not grow. If you don't want a box to grow, use hfill(int)/ vfill(int).

vshrink(int) plays a similar role when shrinking a box below its preferred height.

Returns:
this
Throws:
IllegalArgumentException - if weight <= 0 or > MAX_WEIGHT_SHRINK.
See Also:
hweight(int), MSBLayout.Constraints.vweight(), vshrink(int)

hshrink

MSBLayout.MutableConstraints hshrink(int weight)
When boxes are shrunk below their preferred sizes because their container is too small, the weight value determines the relative amount of space this Box will lose. You can think of this value as specifying how fast the box will shrink in relation to other boxes in the same container. A box with twice the hshrink() value, will lose twice the space. The value is always >0 and <=MAX_WEIGHT_SHRINK and can be set independently for horizontal (hshrink) and vertical space (vshrink). hweight(int) plays a similar role when growing a box larger than its preferred width.

NOTE: When you find that the hshrink value seems to have no effect, this may be due to one of the following reasons:

Returns:
this
Throws:
IllegalArgumentException - if weight <= 0 or > MAX_WEIGHT_SHRINK.
See Also:
vshrink(int), MSBLayout.Constraints.hshrink(), hweight(int)

vshrink

MSBLayout.MutableConstraints vshrink(int weight)
When boxes are shrunk below their preferred sizes because their container is too small, the weight value determines the relative amount of space this Box will lose. You can think of this value as specifying how fast the box will shrink in relation to other boxes in the same container. A box with twice the vshrink() value, will lose twice the space. The value is always >0 and <=MAX_WEIGHT_SHRINK and can be set independently for horizontal (hshrink) and vertical space (vshrink). vweight(int) plays a similar role when growing a box larger than its preferred height.

NOTE: When you find that the vshrink value seems to have no effect, this may be due to one of the following reasons:

Returns:
this
Throws:
IllegalArgumentException - if weight <= 0 or > MAX_WEIGHT_SHRINK.
See Also:
hshrink(int), MSBLayout.Constraints.vshrink(), vweight(int)

halign

MSBLayout.MutableConstraints halign(float a)
When this box is contained in a box that has excess blank space, the alignment determines where that blank space will be relative to this box.

An alignment < 0 means "justify", i.e. if this box is the first or the last in the container box, it will touch at least one edge of the container, otherwise it will be positioned exactly in the middle between its two sibling boxes. An alignment between 0.0 and 1.0 specifies the percentage of all blank space that is to be placed before this box. E.g an alignment of 0.5 means that 50% of the empty space will be placed before the Box and 50% after it. Note that this will not necessarily result in the Box being in the exact center of the container box, because the presence of sibling boxes will affect its placement, too. Alignments >1.0 mean the same as 1.0.

In no event will alignment cause 2 boxes to overlap. E.g. 2 sibling boxes with alignment 0.5 will not overlap each other. Instead they will form a cluster that is as a whole centered (with respect to the empty space, not necessarily with respect to the parent container). If the alignment of a box is less than the alignment of a sibling box that comes before it, its alignment will be assumed to be the same as the sibling.

The alignment can be set independently for horizontal (halign) and vertical alignment (valign).

MSBLayout.setSingleBoxJustifyBehaviour(float, float, int, int) controls how the special case of a single box without siblings is handled when its alignment is "justify".

Returns:
this
See Also:
MSBLayout.Constraints.halign(), valign(float)

valign

MSBLayout.MutableConstraints valign(float a)
When this box is contained in a box that has excess blank space, the alignment determines where that blank space will be relative to this box. See halign(float) for a detailed explanation of alignment.

Returns:
this
See Also:
MSBLayout.Constraints.valign(), halign(float)

setConstraints

MSBLayout.MutableConstraints setConstraints(MSBLayout.Constraints orig)
Copies the settings from orig to this MutableConstraints object.

Returns:
this

hfill

MSBLayout.MutableConstraints hfill(int fill)
Sets the box's willingness to grow horizontally to fill excess space. 0 means the Box insists on its preferred size. 1 means this Box is willing to grow to its maximum size if required. 2 means the Box is willing to grow beyond its maximum size if there is still too much space after all boxes with willingness == 1 have been grown to their max sizes.

Returns:
this
Throws:
IllegalArgumentException - if the number passed is not 0, 1 or 2.
See Also:
vfill(int), MSBLayout.Constraints.hfill()

vfill

MSBLayout.MutableConstraints vfill(int fill)
Sets the box's willingness to grow vertically to fill excess space. 0 means the Box insists on its preferred size. 1 means this Box is willing to grow to its maximum size if required. 2 means the Box is willing to grow beyond its maximum size if there is still too much space after all boxes with willingness == 1 have been grown to their max sizes.

Returns:
this
Throws:
IllegalArgumentException - if the number passed is not 0, 1 or 2.
See Also:
hfill(int), MSBLayout.Constraints.vfill()

hscale

MSBLayout.MutableConstraints hscale(float scale)
A box that is part of a Group with tieWidth() uses the group's tied minimum, preferred and maximum widths multiplied by this factor. You would use this feature when building a grid with same size cells to simulate merged cells.

Returns:
this
See Also:
MSBLayout.Constraints.hscale(), vscale(float)

vscale

MSBLayout.MutableConstraints vscale(float scale)
A box that is part of a Group with tieHeight() uses the group's tied minimum, preferred and maximum heights multiplied by this factor. You would use this feature when building a grid with same size cells to simulate merged cells.

Returns:
this
See Also:
hscale(float), MSBLayout.Constraints.vscale()


Copyright © 2010 Matthias S. Benkmann. See LICENSE file for licensing details.
Hosted on Get MSBLayout at SourceForge.net. Fast, secure and Free Open Source software downloads