Class CellConstraints
- java.lang.Object
-
- net.sf.jguiraffe.gui.layout.CellConstraints
-
- All Implemented Interfaces:
Serializable
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:- The alignment of the represented cell. This can be one of the constants
defined by the
CellAlignment
enumeration class. - An initial size. This property defines how the column's or row's size
depends on the sizes of the contained components. The possible values are
defined by the enumeration class
CellSize
. - A minimum size for this cell. This is a numeric value specifying the minimum width for columns and minimum height for rows. To determine the size of a column or row the layout first calculates the initial size. If this is less than the minimum size, the minimum size is used. It is possible to use different units for specifying this property.
- A weight factor. This factor determines how this cell should behave if
additional space becomes available when the container's size changes (e.g. if
the user resizes the window). If this factor is 0, the cell won't change its
size; it will always keep its initial size. For other values than 0 the
remaining space is given to the affected cells with regard to their factors.
It is recommended to use percentage values for these factors, which sum up to
100 percent (hence the name of the
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
: ACellConstraints
object is created with theCellSize
MINIMUM
and the alignmentCENTER
. 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. TheCellSize
is automatically set toNONE
.
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.- Version:
- $Id: CellConstraints.java 205 2012-01-29 18:29:57Z oheger $
- Author:
- Oliver Heger
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
CellConstraints.Builder
A builder class for creating instances ofCellConstraints
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method 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 thisCellConstraints
object.String
toString()
Returns a string representation of this constraints object.
-
-
-
Method Detail
-
getAlignment
public CellAlignment getAlignment()
Returns the alignment string.- Returns:
- the alignment string
-
getCellSize
public CellSize getCellSize()
Returns the size of the cell.- Returns:
- the cell size
-
getMinSize
public NumberWithUnit getMinSize()
Returns the minimum size.- Returns:
- the minimum size
-
getWeight
public int getWeight()
Returns the weight factor.- Returns:
- the weight factor
-
toSpecificationString
public String toSpecificationString()
Returns a string specification for thisCellConstraints
object. This string conforms to the definition given in the class comment. It can be passed to aBuilder
instance to obtain a correspondingCellConstraints
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.- Returns:
- a specification string for this instance
-
toString
public String toString()
Returns a string representation of this constraints object. This string contains the specification string produced bytoSpecificationString()
.
-
equals
public boolean equals(Object obj)
Compares this object with another one. Two instances ofCellConstraints
are equal if all of their properties are equal.
-
-