Package com.jgoodies.forms.layout
Class ConstantSize
- java.lang.Object
-
- com.jgoodies.forms.layout.ConstantSize
-
- All Implemented Interfaces:
Size
,java.io.Serializable
public final class ConstantSize extends java.lang.Object implements Size, java.io.Serializable
An implementation of theSize
interface that represents constant sizes described by a value and unit, for example: 10 pixel, 15 point or 4 dialog units. You can get instances ofConstantSize
using the factory methods and constants in theSizes
class. Logical constant sizes that vary with the current layout style are delivered by theLayoutStyle
class.This class supports different size units:
Unit Abbreviation Size Millimeter mm 0.1 cm Centimeter cm 10.0 mm Inch in 25.4 mm DTP Point pt 1/72 in Pixel px 1/(resolution in dpi) in Dialog Unit dlu honors l&f, resolution, and dialog font size Examples:
Sizes.ZERO; Sizes.DLUX9; Sizes.dluX(42); Sizes.pixel(99);
- Version:
- $Revision: 1.21 $
- See Also:
Size
,Sizes
, Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
ConstantSize.Unit
An ordinal-based serializable typesafe enumeration for units as used in instances ofConstantSize
.
-
Field Summary
Fields Modifier and Type Field Description static ConstantSize.Unit
CENTIMETER
static ConstantSize.Unit
CM
static ConstantSize.Unit
DIALOG_UNITS_X
static ConstantSize.Unit
DIALOG_UNITS_Y
static ConstantSize.Unit
DLUX
static ConstantSize.Unit
DLUY
static ConstantSize.Unit
IN
static ConstantSize.Unit
INCH
static ConstantSize.Unit
MILLIMETER
static ConstantSize.Unit
MM
static ConstantSize.Unit
PIXEL
static ConstantSize.Unit
POINT
static ConstantSize.Unit
PT
static ConstantSize.Unit
PX
private ConstantSize.Unit
unit
private double
value
private static ConstantSize.Unit[]
VALUES
An array of all enumeration values used to canonicalize deserialized units.
-
Constructor Summary
Constructors Constructor Description ConstantSize(double value, ConstantSize.Unit unit)
Constructs a ConstantSize for the given size and unit.ConstantSize(int value, ConstantSize.Unit unit)
Constructs a ConstantSize for the given size and unit.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
compressible()
Describes if this Size can be compressed, if container space gets scarce.(package private) static ConstantSize
dluX(int value)
Creates and returns a ConstantSize for the specified size value in horizontal dialog units.(package private) static ConstantSize
dluY(int value)
Creates and returns a ConstantSize for the specified size value in vertical dialog units.java.lang.String
encode()
Returns a parseable string representation of this constant size.boolean
equals(java.lang.Object o)
Indicates whether some other ConstantSize is "equal to" this one.int
getPixelSize(java.awt.Component component)
Converts the size if necessary and returns the value in pixels.ConstantSize.Unit
getUnit()
Returns this size's unit.double
getValue()
Returns this size's value.int
hashCode()
Returns a hash code value for the object.private int
intValue()
int
maximumSize(java.awt.Container container, java.util.List components, FormLayout.Measure minMeasure, FormLayout.Measure prefMeasure, FormLayout.Measure defaultMeasure)
Returns this size as pixel size.private static java.lang.String[]
splitValueAndUnit(java.lang.String encodedValueAndUnit)
Splits a string that encodes size with unit into the size and unit substrings.java.lang.String
toString()
Returns a string representation of this size object.(package private) static ConstantSize
valueOf(java.lang.String encodedValueAndUnit, boolean horizontal)
Creates and returns a ConstantSize from the given encoded size and unit description.
-
-
-
Field Detail
-
PIXEL
public static final ConstantSize.Unit PIXEL
-
POINT
public static final ConstantSize.Unit POINT
-
DIALOG_UNITS_X
public static final ConstantSize.Unit DIALOG_UNITS_X
-
DIALOG_UNITS_Y
public static final ConstantSize.Unit DIALOG_UNITS_Y
-
MILLIMETER
public static final ConstantSize.Unit MILLIMETER
-
CENTIMETER
public static final ConstantSize.Unit CENTIMETER
-
INCH
public static final ConstantSize.Unit INCH
-
PX
public static final ConstantSize.Unit PX
-
PT
public static final ConstantSize.Unit PT
-
DLUX
public static final ConstantSize.Unit DLUX
-
DLUY
public static final ConstantSize.Unit DLUY
-
MM
public static final ConstantSize.Unit MM
-
CM
public static final ConstantSize.Unit CM
-
IN
public static final ConstantSize.Unit IN
-
VALUES
private static final ConstantSize.Unit[] VALUES
An array of all enumeration values used to canonicalize deserialized units.
-
value
private final double value
-
unit
private final ConstantSize.Unit unit
-
-
Constructor Detail
-
ConstantSize
public ConstantSize(int value, ConstantSize.Unit unit)
Constructs a ConstantSize for the given size and unit.- Parameters:
value
- the size value interpreted in the given unitsunit
- the size's unit- Since:
- 1.1
-
ConstantSize
public ConstantSize(double value, ConstantSize.Unit unit)
Constructs a ConstantSize for the given size and unit.- Parameters:
value
- the size value interpreted in the given unitsunit
- the size's unit- Since:
- 1.1
-
-
Method Detail
-
valueOf
static ConstantSize valueOf(java.lang.String encodedValueAndUnit, boolean horizontal)
Creates and returns a ConstantSize from the given encoded size and unit description.- Parameters:
encodedValueAndUnit
- the size's value and unit as string, trimmed and in lower casehorizontal
- true for horizontal, false for vertical- Returns:
- a constant size for the given encoding and unit description
- Throws:
java.lang.IllegalArgumentException
- if the unit requires integer but the value is not an integer
-
dluX
static ConstantSize dluX(int value)
Creates and returns a ConstantSize for the specified size value in horizontal dialog units.- Parameters:
value
- size value in horizontal dialog units- Returns:
- the associated Size instance
-
dluY
static ConstantSize dluY(int value)
Creates and returns a ConstantSize for the specified size value in vertical dialog units.- Parameters:
value
- size value in vertical dialog units- Returns:
- the associated Size instance
-
getValue
public double getValue()
Returns this size's value.- Returns:
- the size value
- Since:
- 1.1
-
getUnit
public ConstantSize.Unit getUnit()
Returns this size's unit.- Returns:
- the size unit
- Since:
- 1.1
-
getPixelSize
public int getPixelSize(java.awt.Component component)
Converts the size if necessary and returns the value in pixels.- Parameters:
component
- the associated component- Returns:
- the size in pixels
-
maximumSize
public int maximumSize(java.awt.Container container, java.util.List components, FormLayout.Measure minMeasure, FormLayout.Measure prefMeasure, FormLayout.Measure defaultMeasure)
Returns this size as pixel size. Neither requires the component list nor the specified measures.Invoked by
FormSpec
to determine the size of a column or row.- Specified by:
maximumSize
in interfaceSize
- Parameters:
container
- the layout containercomponents
- the list of components used to compute the sizeminMeasure
- the measure that determines the minimum sizesprefMeasure
- the measure that determines the preferred sizesdefaultMeasure
- the measure that determines the default sizes- Returns:
- the computed maximum size in pixel
-
compressible
public boolean compressible()
Describes if this Size can be compressed, if container space gets scarce. Used by the FormLayout size computations in#compressedSizes
to check whether a column or row can be compressed or not.ConstantSizes are incompressible.
- Specified by:
compressible
in interfaceSize
- Returns:
false
- Since:
- 1.1
-
equals
public boolean equals(java.lang.Object o)
Indicates whether some other ConstantSize is "equal to" this one.- Overrides:
equals
in classjava.lang.Object
- Parameters:
o
- the Object with which to compare- Returns:
true
if this object is the same as the obj argument;false
otherwise.- See Also:
Object.hashCode()
,Hashtable
-
hashCode
public int hashCode()
Returns a hash code value for the object. This method is supported for the benefit of hashtables such as those provided byjava.util.Hashtable
.- Overrides:
hashCode
in classjava.lang.Object
- Returns:
- a hash code value for this object.
- See Also:
Object.equals(java.lang.Object)
,Hashtable
-
toString
public java.lang.String toString()
Returns a string representation of this size object. Note: This string representation may change at any time. It is intended for debugging purposes. For parsing, useencode()
instead.- Overrides:
toString
in classjava.lang.Object
- Returns:
- a string representation of the constant size
-
encode
public java.lang.String encode()
Returns a parseable string representation of this constant size.
-
intValue
private int intValue()
-
splitValueAndUnit
private static java.lang.String[] splitValueAndUnit(java.lang.String encodedValueAndUnit)
Splits a string that encodes size with unit into the size and unit substrings. Returns an array of two strings.- Parameters:
encodedValueAndUnit
- a strings that represents a size with unit, trimmed and in lower case- Returns:
- the first element is size, the second is unit
-
-