Class FormSpec
- java.lang.Object
-
- com.jgoodies.forms.layout.FormSpec
-
- All Implemented Interfaces:
java.io.Serializable
- Direct Known Subclasses:
ColumnSpec,RowSpec
public abstract class FormSpec extends java.lang.Object implements java.io.SerializableAn abstract class that specifies columns and rows in FormLayout by their default alignment, start size and resizing behavior. API users will use the subclassesColumnSpecandRowSpec.Also implements the parser for encoded column and row specifications and provides parser convenience behavior for its subclasses ColumnSpec and RowSpec.
TODO: Consider extracting the parser role to a separate class.
- Version:
- $Revision: 1.25 $
- See Also:
ColumnSpec,RowSpec,FormLayout,CellConstraints, Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classFormSpec.DefaultAlignmentAn ordinal-based serializable typesafe enumeration for the column and row default alignment types.
-
Field Summary
Fields Modifier and Type Field Description (package private) static FormSpec.DefaultAlignmentBOTTOM_ALIGNBy default put the components in the bottom.private static java.util.regex.PatternBOUNDS_SEPARATOR_PATTERN(package private) static FormSpec.DefaultAlignmentCENTER_ALIGNBy default put the components in the center.static doubleDEFAULT_GROWThe default resize weight.private FormSpec.DefaultAlignmentdefaultAlignmentHolds the default alignment that will be used if a cell does not override this default.private booleandefaultAlignmentExplicitlySetDescribes whether the default alignment has been explictly set.(package private) static FormSpec.DefaultAlignmentFILL_ALIGNBy default fill the column or row.(package private) static FormSpec.DefaultAlignmentLEFT_ALIGNBy default put components in the left.(package private) static FormSpec.DefaultAlignmentNO_ALIGNA special alignment intended for table columns only, where some cell renderers are not aligned.static doubleNO_GROWGives a column or row a fixed size.private doubleresizeWeightHolds the resize weight; is 0 if not used.(package private) static FormSpec.DefaultAlignmentRIGHT_ALIGNBy default put components in the right.private SizesizeHolds the size that describes how to size this column or row.private static java.util.regex.PatternTOKEN_SEPARATOR_PATTERN(package private) static FormSpec.DefaultAlignmentTOP_ALIGNBy default put the components in the top.private static FormSpec.DefaultAlignment[]VALUESAn array of all enumeration values used to canonicalize deserialized default alignments.
-
Constructor Summary
Constructors Modifier Constructor Description protectedFormSpec(FormSpec.DefaultAlignment defaultAlignment, Size size, double resizeWeight)Constructs aFormSpecfor the given default alignment, size, and resize weight.protectedFormSpec(FormSpec.DefaultAlignment defaultAlignment, java.lang.String encodedDescription)Constructs a FormSpec from the specified encoded description.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description (package private) booleancanGrow()Checks and answers whether this spec can grow or not.java.lang.Stringencode()Returns a short and parseable string representation of this form specification.FormSpec.DefaultAlignmentgetDefaultAlignment()Returns the default alignment.booleangetDefaultAlignmentExplictlySet()Returns whether the default alignment has been explicitly set or not.doublegetResizeWeight()Returns the current resize weight.SizegetSize()Returns the size.private static booleanisConstant(Size aSize)(package private) abstract booleanisHorizontal()Returns if this is a horizontal specification (vs.(package private) intmaximumSize(java.awt.Container container, java.util.List components, FormLayout.Measure minMeasure, FormLayout.Measure prefMeasure, FormLayout.Measure defaultMeasure)Computes the maximum size for the given list of components, using this form spec and the specified measure.private voidparseAndInitValues(java.lang.String encodedDescription)Parses an encoded form specification and initializes all required fields.private SizeparseAtomicSize(java.lang.String token)Decodes and returns an atomic size that is either a constant size or a component size.private SizeparseBoundedSize(java.lang.String token)private SizeparseOldBoundedSize(java.lang.String token, boolean setMax)Parses an encoded compound size and sets the size fields.private static doubleparseResizeWeight(java.lang.String token)Decodes an encoded resize mode and resize weight and answers the resize weight.private SizeparseSize(java.lang.String token)Parses an encoded size spec and returns the size.(package private) voidsetDefaultAlignment(FormSpec.DefaultAlignment defaultAlignment)(package private) voidsetResizeWeight(double resizeWeight)(package private) voidsetSize(Size size)java.lang.StringtoShortString()Returns a string representation of this form specification.java.lang.StringtoString()Returns a string representation of this form specification.
-
-
-
Field Detail
-
LEFT_ALIGN
static final FormSpec.DefaultAlignment LEFT_ALIGN
By default put components in the left.
-
RIGHT_ALIGN
static final FormSpec.DefaultAlignment RIGHT_ALIGN
By default put components in the right.
-
TOP_ALIGN
static final FormSpec.DefaultAlignment TOP_ALIGN
By default put the components in the top.
-
BOTTOM_ALIGN
static final FormSpec.DefaultAlignment BOTTOM_ALIGN
By default put the components in the bottom.
-
CENTER_ALIGN
static final FormSpec.DefaultAlignment CENTER_ALIGN
By default put the components in the center.
-
FILL_ALIGN
static final FormSpec.DefaultAlignment FILL_ALIGN
By default fill the column or row.
-
NO_ALIGN
static final FormSpec.DefaultAlignment NO_ALIGN
A special alignment intended for table columns only, where some cell renderers are not aligned.
-
VALUES
private static final FormSpec.DefaultAlignment[] VALUES
An array of all enumeration values used to canonicalize deserialized default alignments.
-
NO_GROW
public static final double NO_GROW
Gives a column or row a fixed size.- See Also:
- Constant Field Values
-
DEFAULT_GROW
public static final double DEFAULT_GROW
The default resize weight.- See Also:
- Constant Field Values
-
TOKEN_SEPARATOR_PATTERN
private static final java.util.regex.Pattern TOKEN_SEPARATOR_PATTERN
-
BOUNDS_SEPARATOR_PATTERN
private static final java.util.regex.Pattern BOUNDS_SEPARATOR_PATTERN
-
defaultAlignment
private FormSpec.DefaultAlignment defaultAlignment
Holds the default alignment that will be used if a cell does not override this default.
-
defaultAlignmentExplicitlySet
private boolean defaultAlignmentExplicitlySet
Describes whether the default alignment has been explictly set.- See Also:
getDefaultAlignmentExplictlySet()
-
size
private Size size
Holds the size that describes how to size this column or row.
-
resizeWeight
private double resizeWeight
Holds the resize weight; is 0 if not used.
-
-
Constructor Detail
-
FormSpec
protected FormSpec(FormSpec.DefaultAlignment defaultAlignment, Size size, double resizeWeight)
Constructs aFormSpecfor the given default alignment, size, and resize weight. The resize weight must be a non-negative double; you can useNONEas a convenience value for no resize.- Parameters:
defaultAlignment- the spec's default alignmentsize- a constant, component or bounded sizeresizeWeight- the spec resize weight- Throws:
java.lang.NullPointerException- if thesizeisnulljava.lang.IllegalArgumentException- if theresizeWeightis negative
-
FormSpec
protected FormSpec(FormSpec.DefaultAlignment defaultAlignment, java.lang.String encodedDescription)
Constructs a FormSpec from the specified encoded description. The description will be parsed to set initial values.- Parameters:
defaultAlignment- the default alignmentencodedDescription- the encoded description
-
-
Method Detail
-
getDefaultAlignment
public final FormSpec.DefaultAlignment getDefaultAlignment()
Returns the default alignment.- Returns:
- the default alignment
-
getDefaultAlignmentExplictlySet
public final boolean getDefaultAlignmentExplictlySet()
Returns whether the default alignment has been explicitly set or not.- Returns:
trueif the default alignment has been provided during the parse process,falseif the default alignment has been set by the constructor at the instance creation time
-
getSize
public final Size getSize()
Returns the size.- Returns:
- the size
-
getResizeWeight
public final double getResizeWeight()
Returns the current resize weight.- Returns:
- the resize weight.
-
canGrow
final boolean canGrow()
Checks and answers whether this spec can grow or not. That is the case if and only if the resize weight is !=NO_GROW.- Returns:
- true if it can grow, false if it can't grow
-
isHorizontal
abstract boolean isHorizontal()
Returns if this is a horizontal specification (vs. vertical). Used to distinct between horizontal and vertical dialog units, which have different conversion factors.- Returns:
- true for horizontal, false for vertical
-
setDefaultAlignment
void setDefaultAlignment(FormSpec.DefaultAlignment defaultAlignment)
-
setSize
void setSize(Size size)
-
setResizeWeight
void setResizeWeight(double resizeWeight)
-
parseAndInitValues
private void parseAndInitValues(java.lang.String encodedDescription)
Parses an encoded form specification and initializes all required fields. The encoded description must be in lower case.- Parameters:
encodedDescription- the FormSpec in an encoded format- Throws:
java.lang.NullPointerException- ifencodedDescriptionisnulljava.lang.IllegalArgumentException- ifencodedDescriptionis empty, whitespace, has no size, or is otherwise invalid
-
parseSize
private Size parseSize(java.lang.String token)
Parses an encoded size spec and returns the size.- Parameters:
token- a token that represents a size, either bounded or plain- Returns:
- the decoded Size
-
parseBoundedSize
private Size parseBoundedSize(java.lang.String token)
-
parseOldBoundedSize
private Size parseOldBoundedSize(java.lang.String token, boolean setMax)
Parses an encoded compound size and sets the size fields. The compound size has format: max(<atomic size>;<atomic size2>) | min(<atomic size1>;<atomic size2>) One of the two atomic sizes must be a logical size, the other must be a size constant.- Parameters:
token- a token for a bounded size, e.g. "max(50dlu; pref)"setMax- if true we set a maximum size, otherwise a minimum size- Returns:
- a Size that represents the parse result
-
parseAtomicSize
private Size parseAtomicSize(java.lang.String token)
Decodes and returns an atomic size that is either a constant size or a component size.- Parameters:
token- the encoded size- Returns:
- the decoded size either a constant or component size
-
parseResizeWeight
private static double parseResizeWeight(java.lang.String token)
Decodes an encoded resize mode and resize weight and answers the resize weight.- Parameters:
token- the encoded resize weight- Returns:
- the decoded resize weight
- Throws:
java.lang.IllegalArgumentException- if the string description is an invalid string representation
-
isConstant
private static boolean isConstant(Size aSize)
-
toString
public final java.lang.String toString()
Returns a string representation of this form specification. The string representation consists of three elements separated by a colon (":"), first the alignment, second the size, and third the resize spec.This method does not return an encoded version of this object; the contrary is the case. Many instances will return a string that cannot be parsed.
Note: The string representation may change at any time. For parsing use
encode()instead.- Overrides:
toStringin classjava.lang.Object- Returns:
- a string representation of the form specification.
-
toShortString
public final java.lang.String toShortString()
Returns a string representation of this form specification. The string representation consists of three elements separated by a colon (":"), first the alignment, second the size, and third the resize spec.This method does not return an encoded version of this object; the contrary is the case. Many instances will return a string that cannot be parsed.
Note: The string representation may change at any time. For parsing use
encode()instead.- Returns:
- a string representation of the form specification.
-
encode
public final java.lang.String encode()
Returns a short and parseable string representation of this form specification. The string will omit the alignment and resize specifications if these are the default values.- Returns:
- a string representation of the form specification.
- Since:
- 1.2
- See Also:
for a more verbose string representation
-
maximumSize
final int maximumSize(java.awt.Container container, java.util.List components, FormLayout.Measure minMeasure, FormLayout.Measure prefMeasure, FormLayout.Measure defaultMeasure)Computes the maximum size for the given list of components, using this form spec and the specified measure.Invoked by FormLayout to determine the size of one of my elements
- Parameters:
container- the layout containercomponents- the list of components to measureminMeasure- the measure used to determine the minimum sizeprefMeasure- the measure used to determine the preferred sizedefaultMeasure- the measure used to determine the default size- Returns:
- the maximum size in pixels
-
-