public final class CellConstraints extends Object implements Serializable
A class for describing column and row constraints for the
PercentLayout
layout manager.
Objects of this class define properties for the single columns and rows that
comprise the layout maintained by PercentLayout
. Supported properties
are:
CellAlignment
enumeration class.CellSize
.PercentLayout
layout manager).
Then it is easy to understand that each cell with a weight factor greater
than 0 is granted as much percent of the remaining space.
Instances of this class are not created directly, but the inner Builder
class is used for this purpose (an application of the
builder pattern). A typical invocation sequence could look as
follows:
CellConstraints.Builder ccb = new CellConstraints.Builder(); CellConstraints cc = ccb.withCellSize(CellSize.Preferred).withMinimumSize( new NumberWithUnit(20, Unit.PIXEL)).withWeight(25).withCellAlignment( CellAlignment.FULL).create();
For instances of this class a string representation is defined. Strings conforming to the format explained below can also be passed to the builder for creating instances:
CONSTRAINT ::= [ALIGN"/"]SIZE["/"WEIGHT] SIZE ::= INITSIZE | MINSIZE | BOTHSIZES BOTHSIZES ::= INITSIZE "(" MINSIZE ")" INITSIZE ::= "PREFERRED" | "MINIMUM" | "NONE" MINSIZE ::= <Positive number> [UNIT] UNIT ::= "px" | "cm" | "in" | "dlu" ALIGN ::= "START" | "CENTER" | "END" | "FULL" WEIGHT ::= <Positive number>Here are some examples:
PREFERRED
: only the cell size is set, the other properties are
set to default values.CENTER/MINIMUM(20px)/33
: A CellConstraints
object is
created with the CellSize
MINIMUM
and the alignment CENTER
. The minimum size is set to 20 pixels, and the weight factor is set
to 33.(20)
: Here only the minimum size of the cell is set. The
CellSize
is automatically set to NONE
.
Instances of this class are immutable and thus can be shared between multiple
threads. The Builder
class makes use of this feature and caches the
instances that have been created. So if another constraint with already used
properties is requested, a shared instance can be returned.
Modifier and Type | Class and Description |
---|---|
static class |
CellConstraints.Builder
A builder class for creating instances of
CellConstraints . |
Modifier and Type | Method and Description |
---|---|
boolean |
equals(Object obj)
Compares this object with another one.
|
CellAlignment |
getAlignment()
Returns the alignment string.
|
CellSize |
getCellSize()
Returns the size of the cell.
|
NumberWithUnit |
getMinSize()
Returns the minimum size.
|
int |
getWeight()
Returns the weight factor.
|
int |
hashCode()
Returns a hash code for this object.
|
String |
toSpecificationString()
Returns a string specification for this
CellConstraints object. |
String |
toString()
Returns a string representation of this constraints object.
|
public CellAlignment getAlignment()
public CellSize getCellSize()
public NumberWithUnit getMinSize()
public int getWeight()
public String toSpecificationString()
CellConstraints
object.
This string conforms to the definition given in the class comment. It can
be passed to a Builder
instance to obtain a corresponding CellConstraints
instance. The string returned by this method contains
the values of all properties of this object, even if some have been set
to default values.public String toString()
toSpecificationString()
.public boolean equals(Object obj)
CellConstraints
are equal if all of their properties are equal.Copyright © 2016 The JGUIraffe Team. All rights reserved.